┌──────────────────────────────────────────┐ │ ──SELECT;─┴WHEN─expression─┬─┬─THEN─┬─┬───instruction┴── └;┘ └;┘ ─────┬────────────────────────────────────┬───END;───── └─OTHERWISE─┬─┬─┬───────────────────┬┘ └;┘ │ ┌─────────────┐ │ │ │ │ └──┴─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: