Switch
Username:  
Password:
  > Home
v User Guide
    > Introduction
    > Hello World
    v Flow Control
       o If-else
       o Switch
       o Foreach loop
       o While loop
       o For loop
    > Function Calls
    > Authentication
    > Database access
    > Content Management
    > Remote Calling
    > Object-Oriented
    > Other Features
> Reference
> Portal Object
> Development Guide


Shortcuts
sys Class
debug Class
Intrinsic Conversions
>> User Guide >> Flow Control >> Switch <=  =>      <  1  >  
Switch

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.

 

Previous Page       Next Page

Accsoft Computer Technology Pty Ltd     ABN: 98 065 617 549
PO Box 892, Epping NSW 1710         Level 1, Epping Office Park, 242 Beecroft Rd, Epping NSW 2121, Australia
Tel: Sydney - (02)98691668     National - 1300-881668         Fax: (02)98691866
© Copyright 2003 Accsoft Computer Technology Pty Ltd