Navigation:  Reference > Structured Programming Commands >

SELECT

Print this Topic Previous pageReturn to chapter overviewNext page

 

This is a non-loop structure.  Each item is only tested once.  The general layout of the structure is:

 

SELECT expression

 

 CASE int_value

 CASE int_value

 ...

 CASE int_value

 OTHERWISE

 

ENDC

 

SELECT expression

       This is the beginning of the Case structure.  The expression must resolve to an I type value.  The value will be used in comparisons by the individual CASE commands.

 

       This command is generally used in menu type situations where there is a list of options.

 

CASE int_value

       This part represents the choice in the SELECT structure.  The int_value must be in the form of an I type constant.  For example:

 

               CASE 1

 

       If the int_value matches the value generated by the appropriate SELECT expression, the lines after the CASE command and continuing until the next CASE, OTHERWISE or ENDC command will be executed.  Otherwise control will be passed to the next subsequent CASE, OTHERWISE, or ENDC command.

 

       There can be any number of CASE commands within a SELECT/CASE/ENDC structure.  However, only one will be executed, and that will be the first one for which the int_value matches the value in the SELECT expression.

 

OTHERWISE

       If none of the previous CASE values match that in the SELECT command, the program will always execute the lines between this OTHERWISE and the ENDC.  This is much like the ELSE option within an IF/ENDIF structure.

 

ENDC

       This is the end of the SELECT/CASE/ENDC structure.  Each SELECT must have an ENDC to finish the structure.  If the ENDC is not included an error message will be displayed during compilation.

 

EXAMPLE

The following example shows the proper way to use this structure:

 

SELECT counter     && counter might be a value received from a menu.

  CASE 1

    ...

    ...        && group 1

    ...

  CASE 2

    ...

    ...        && group 2

    ...

  CASE 3

    ...

    ...        && group 3

    ...

  OTHERWISE

    ...

    ...        && group 4

    ...

ENDC

 

(The indentations are for clarity only.)  In the example above if counter = 1 the lines in group 1 will be executed, if counter = 2 group 2, and if counter = 3 group 3.  Otherwise the command lines in group 4 will be executed.

 

 


Page url: http://www.cassoftware.com/tas/manual/select2.htm