<< Click to Display Table of Contents >> Home mIoTa BASIC > mIoTa BASIC Language Reference > Statements > Conditional Statements > CASE Statements |
You can use the CASE statement to pass control to a specific program branch, based on a certain condition.
The CASE statement consists of a selector variable and a list of possible values. The syntax of the CASE statement is:
case selector_variable is value_1 then statement_1; ... is value_n then statement_n; [else default_statement;] caseend; |
The selector_variable is a numerical variable and the statements can be any statements.The ELSE clause is optional.
The CASE statement compares the selector_variable value against all available values. If a match is found, the statement following the match executes, and the case statement terminates. In case there are multiple matches, the first matching statement will be executed. If none of values match the selector value, then default_statement in the ELSE clause (if there is one) is executed.
Here’s a simple example of the case statement ..
case u1 // check contents of u1 is 5 then mystr = 'me'; // if u1 is 5 then set mystr to 'me' is 7 then mystr = 'you'; // if u1 is 7 then set mystr to 'you' else mystr = 'no one'; caseend; |
© 2018 Swintechnics