Select Statements

selectstmt ::= Select expression From [[ caseblock ]] [ owiseblock ] EndSelect ;

caseblock ::= Case condition [[ , condition ]] Do stmtblock

condition ::= constexpr [ To constexpr ]

owiseblock ::= Otherwise stmtblock

The expression is any expression that yields a value with a type that matches the type of the Case labels. These can be either Number or an enumerated type. If the number is not an integer there is a risk that rounding errors will cause a match to fail.

The constexpr is a constant expression that can be evaluated at compile time.

When a Select statements is executed the system will go through each case test list in turn. If any of the checks match then all the statement up to the next case label will be treated as the statement block. Once one Case has execute the rest of the blocks are skipped. If no cases match and there is an Otherwise block then that block will be executed.

Only the first matching Case will be executed even if there are overlapping conditions that would also match.

If it is expected that the expression could yield Null this case can be tested for Explicitly :-

Case Null Do

Such a test should always occur before any range test.

	Select i From

	    Case 1 Do
		Output "First case";
	    Case 2 Do
		Output "Second case";
		Output "Yes, more than one statement allowed";

	    Case 3 To 10, 20, 30 Do
		Output "Range case";

		Output "No matches";