Original Author Paul Laughton, 2011
Page 88
De Re BASIC!
Sw.case <exp>, ...
This form of Sw.case provides a list of one or more expressions. A Sw.case of this form matches the
Sw.begin if the value of at least one of the expressions exactly equals the value of the Sw.begin
parameter. The type of the Sw.begin and Sw.case parameter(s), numeric or string, must match.
Sw.case <op><exp>
The first form of Sw.case, above, matches the Sw.begin if the value of any of its parameters equals the
value of the Sw.begin parameter. This second form can take only one expression <exp>, but it lets you
specify a different logical operator <op>. You may use any of these comparison operators:
< <= > >= <>
For example:
SW.BEGIN a
SW.CASE < b
% This SW.CASE matches if a < b
The expression <exp> may be arbitrarily complex. The whole expression is evaluated as if written:
<value of Sw.begin argument> <op> <exp>
Operator precedence is applied as usual.
Sw.break
This statement may be used to terminate the block of statements that follows Sw.case or Sw.default.
The Sw.break causes BASIC! to jump forward to the Sw.end statement, skipping everything between.
If no Sw.break is present in a particular Sw.case then subsequent Sw.cases will be executed until a
Sw.break or Sw.end is encountered.
Sw.default
This statements acts like a Sw.case that matches any value. If any Sw.case matches the Sw.begin value,
then the Sw.default is ignored, even if the matching Sw.case is after the Sw.default.
A switch is not required to have a Sw.default, but it must not have more than one. A second Sw.default
in the same switch is a syntax error.
Sw.end
The Sw.end terminates a switch operation. Sw.end must eventually follow a Sw.begin.
Interrupt Labels (Event Handlers)
You can perform physical actions that tell your BASIC! program to do something. When you touch the
screen or press a key you cause an event. These events are asynchronous, that is, they happen at times
your program cannot predict. BASIC! detects some events so your program can respond to them.
BASIC! handles events as interrupts. Each event that BASIC! recognizes has a unique Interrupt Label.
When an event occurs, BASIC! looks for the Interrupt Label that matches the event.