0.9b (c) 1995 Peter Childs
+------------------------------------------+ v | >>--SELECT;-+WHEN-expression-+-+-THEN-+-+---instruction+--> +;+ +;+ >-----+------------------------------------+---END;-----> +-OTHERWISE-+-+-+-------------------++ +;+ | +-------------+ | | v | | +--+-instruction-+--+
SELECT is used to conditionally process one of several alternative instructions.
Each expression after a WHEN clause is evaluated in turn and must result in 0 or 1. If the result is 1, the instruction following the THEN clause, which can be a complex instruction such as IF, DO, or SELECT, is processed and control then passes to the END clause. If the result is 0, control passes to the next WHEN clause.
If none of the WHEN expressions evaluate to 1, control passes to the instructions, if any, after OTHERWISE. In this situation, the absence of OTHERWISE causes an error.
Example:
balance = balance - check Select when balance > 0 then say 'Congratulations! You still have' balance 'dollars left.' when balance = 0 then do say 'Warning, Balance is now zero! STOP all spending.' say "You cut it close this month! Hope you don't have any" say "checks left outstanding." end Otherwise say "You have just overdrawn your account." say "Your balance now shows" balance "dollars." say "Oops! Hope the bank doesn't close your account." end /* Select */
Notes:
1. The instruction can be any assignment, command, or keyword instruction, including any of the more complex constructs such as DO, IF, or the SELECT instruction itself.
2. A null clause is not an instruction, so putting an extra semicolon after a WHEN clause is not equivalent to putting a dummy instruction. The NOP instruction is provided for this purpose.
3. The symbol THEN cannot be used within expression, because the keyword THEN is treated differently, in that it need not start a clause. This allows the expression on the WHEN clause to be terminated by the THEN without a ; (delimiter) being required.
Inf-HTML End Run - Successful