The CASE statement allows the programmer to execute a particular sequence of instructions based upon the results of a series of test expressions. It usually takes the form:
BEGIN CASE CASE expression statement(s) CASE expression statement(s) . . . END CASE
- The BEGIN CASE and END CASE statements bound the CASE structure. Within this block, an arbitrary number of CASE expression statements may exist followed by any number of jBASE BASIC statements.
- The expression should evaluate to a TRUE or FALSE result. The evaluation of each expression at execution time is in order. If the expression returns a TRUE result, it then executes the statements below. On completion of the associated statements, execution will resume at the first statement following the END CASE.
- A default action, a form of exception handling may be introduced by using an expression that is always TRUE. This should always be the last expression in the CASE block.
- BREAK is not necessarily required when using CASE in jBC, which may not be so in other languages.
It is worth noting that a CASE statement immediately followed by another CASE statement does not result in cojoining those operations.
An example of use is as below:
0001 BEGIN CASE 0002 CASE A = 2 0003 if A = 2 then no operation will be performed 0004 CASE A = 1 0005 CRT "You won!" 0006 CASE 1 0007 CRT "You came nowhere" 0008 END CASE 0009
In the above scenario, a single comment is printed depending on the value of A. If A is not 1 or 2 then the default CASE 1 rule will be executed as a "catch all".
Go back to jBASE BASIC.