Command "switch" handles multiple cases of value matching.
In the "elseif" example above, we can use "switch" instead:
switch ('{sys%time|strftime:%p}') {
case 'AM':
display "Good morning";
break;
case 'PM':
display "Good afternoon";
break;
default:
display "What?";
break;
}
(The "break" in the last case can be omitted, but it is a good programming practice to always "break" a case unless you do want it to fall through. This prevents unintentional fall-through to new cases subsequently added to the end of the switch block.)
BEE is a tolerant language. Many languages will complain operations between the start of the switch block and the specification of the first case. BEE will not. Any content in this "forbidden zone" will be ignored:
switch ('{sys%time|strftime:%p}') {
diplay "blah blah"; // This will be ignored, not even compiled in
case 'AM':
display "Good morning";
break;
case 'PM':
display "Good afternoon";
break;
default:
display "What?";
break;
}
This is handy but could be risky if you rely on the compiler to pick up this misplaced operations for you. No, BEE just throws them into a black hole.
|