<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > BuiltIn Functions > Numeric functions > Switch |
Description
Returns the first value following the first expression evaluating as True..
Syntax
n = Switch(expr1, NumericVal1 [[, expr2, NumericVal2], ...])
Returns
Number
Parameters
Name |
Type |
Optional |
Meaning |
expr1 |
Number |
No |
Any logical expression valuating to TRUE or FALSE |
NumericVal1 |
Number |
No |
Numeric expression to return in case expr1 valuate to TRUE |
Remarks
If expr1 evaluates TRUE, NumericVal1 is returned, if expr2 evaluates TRUE, NumericVal2 is returned, etc.
Switch returns the matching value parameter from the first TRUE evaluation of the control expressions, evaluated from left to right in the list. Therefore, it would be wise to place the most likely selections at the front of the Switch list to achieve the utmost efficiency. If no expressions evaluate to TRUE, then a zero (0) value is returned.
Only the chosen value (one of NumericVal1, NumericVal2, NumericVal3 …) is evaluated at run-time; the other value parameters are not. This ensures optimum execution speed, as well as the elimination of unanticipated side effects.
Restrictions
See also
Choose$, IF, IIF$, SELECT, Switch$
Examples