$ CaseStatement = Select Case expression case { case}
[ELSE StatementSequence] END SELECT ";"
$ Case = [CASE CaseLabelList ":" StatementSequence]
$ CaseLabelList = CaseLabels {"," CaseLabels}
$ CaseLabels = ConstExpression [ TO ConstExpression]
The Select Case statement provides the statements sequence selection and execution according to the expression value. After the keywords Select Case you need to enter the expression, which value will be checked. The Case blocks contain the values of the expression that are under check. A single Case block may contain:
One value under check.
Several values separated with commas.
A range of values specified using the keyword To.
After you specify the checked value you need to type in a colon and specify a block of statements executed for this Case block.
If the expression value does not match either of the constants specified in the Case blocks, the platform executes a statements sequence from the Else block, if there is one. The checked expression and values specified in the Case blocks should be of one type. Each of the checked values should be used only in one Case block. Values ranges cannot overlap. You can use the following types of expression and constants: Integer, Decimal, Double, Char, String, Boolean.
Sub SelectCaseSample;
Var
a, c: Integer;
Begin
a := 5; c := 0;
Select Case a
Case 1: c := c - 100;
Case 2: c := c - 100;
Case 3: c := c - 100;
Case 4: c := c - 100;
Case 5: c := c + 1;
Case 6: c := c - 100;
Case 7: c := c - 100;
Case 8: c := c - 100;
Case 9: c := c - 100;
Else c := 0;
End Select;
Select Case a
Case 1, 2, 3: c := c - 100;
Case 4, 5, 6: c := c + 1;
Case 7, 8, 9: c := c - 100;
Else c := 0;
End Select;
Select Case a
Case 1 To 3: c := c - 100;
Case 4 To 6: c := c + 1;
Case 7 To 9: c := c - 100;
Else c := 0;
End Select;
End Sub SelectCaseSample;
See also: