Select Statement

Action

Executes statements associated with a particular case from a group of cases.

Syntax

select 
  case boolean-expr 
    statements
  [ case boolean-expr 
    statements ]
  ...
  [ default 
  statements ]
Variable Description
statements One or more statements.
boolean-expr A boolean expression. If TRUE, control passes to the first statement in the clause. See the Notes below.

Notes

  • Use a select statement to execute at most one case from a group.

  • Once the first boolean-expr in the list evaluates to TRUE, its statement is executed and then control passes to the first statement after the select statement.

  • If no boolean-expr evaluates to TRUE, and there is a default label, then control passes to the statement immediately following it. There can be only one default label, and it must be the last label.

Example

[-] testcase selectExample ()
	[ ] INTEGER I = 0, j = 1
	[-] select
		[-] case I == 0 || j == 0 
			[ ] Print ("Either I or j is 0")
		[-] case I == 0  
			[ ] Print ("Only I is 0") 
		[-] default 
			[ ] Print ("Default case") 
	[ ] // This script prints:
	[ ] // Either I or j is 0