10.2. SWITCH statement

SWITCH statement is a control structure that executes one of several blocks of the statements depending on the value of an expression.

Syntax:

[DO] SWITCH <expression>
	CASE <const11>[,<const12>,...]
		<statements>,...
	[ CASE <const21>[,<const22>,...] ]
		<statements>,...
	[ OTHERWISE ]
		<statements>,...
END[SWITCH]

It evaluates <expression>, looks for it's value in CASE constants, and executes associated block of statements. If none of the CASE constants are equal to the expression value, it executes the block of statements following the OTHERWISE statement (if exist).

Only numeric and character constants are allowed in CASE statement.

Note

SWITCH is more effective than similar DO CASE statement.