Navigation:  ThinBASIC Language > thinBasic Functions > String functions >

Switch$

Previous pageReturn to chapter overviewNext page

 

Description

 

Returns the first value following the first expression evaluating as True..

 

Syntax

 

s = Switch$(expr1, StringVal1 [[, expr2, StringVal2], ...])

 

Returns

 

String

 

Parameters

 

Name

Type

Optional

Meaning

expr1

Number

No

Any logical expression valuating to TRUE or FALSE

StringVal1

String

No

String expression to return in case expr1 valuate to TRUE

 

Remarks

 

If expr1 evaluates TRUE, StringVal1 is returned, if expr2 evaluates TRUE, StringVal2 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 an empty string is returned.

 

Only the chosen value (one of StringVal1, StringVal2, StringVal3 …) 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