Equinox Online Help - Language Reference - A to Z
Switch ... End Switch |
|
---|---|
Applies to | |
Syntax | switch TestExpression[statements]end switch Note that you may use EndSwitch instead of End Switch. |
Action | [Statement] The test expression is evaluated. The result determines which statements are executed. |
Scope | Usable anywhere. |
Notes | The Switch statement is a simple and powerful way of writing conditional statements. Each Case expression is compared with TestExpression in turn. If a match is found, then the associated statements are executed and control passes to the line following the End Switch statement. If no Case expressions match TestExpression then any statements associated with the Default statement are executed. Exit Switch causes control to pass to the line following the End Switch statement. Continue Switch branches to the evaluation of the Switch statement again. The Switch statement can greatly simplify complex conditional testing. eg The syntax example is equivalent to the following If structure: number TempVar | declare TempVar You may attach more than one expression to a single Case statement using a list expression, eg: case case1expression, case2expression. If you do not include comparative operator (eg >) then, equals is assumed. You can also use the To operator to specify a range of values, eg: case case1expression to case2expression There is a special form of the Switch statement, which you can use on a form to identify the current field: switch Fieldcase Field1Nameend switchstatementscase Field2Name, Field3Namestatements The special keyword Field matches the name of the current field. Note that you may only use field names in Switch Field statements. |
Category | Flow Control |
See Also | Block_EndBlock, BreakPressed, Continue, Execute, EnableInput, Exit, For...Next, Goto, If_Then, Repeat_Until, Return, Sleep, Subtable, Switch, While_EndWhile |
Example | The following example method chooses a type of birthday card, depending on the age of the recipient. If the person's age is listed in the first Case statement, a special card is sent. Otherwise, children less than ten years old get a child's card and so on. switch agecase 1, 16, 18, 21, 40, 100end switchCardType = "SPECIAL"case < 10CardType = "CHILD"case 30 To 39CardType = "AGEIST"defaultCardType = "NORMAL" Note that an age of one is true for the first and second case expressions. Only the first case would actually be executed. |