Switch

Top  Previous  Next

Description


The Switch statement allows the user to set up a series of Cases and a Default, one of which will be executed, depending on the value of an input argument. For more information, see Flow Control Script Reference.

 

 

Syntax


 

// Variable Switch

Variable a;

Switch (a);

    Case 0:

          // Do something

          Break;

    Case 1:

          // Fall through to next block

    Default:

          // Do something

          Break;

End;

 

// String Switch

String b;

Switch (b);

    Case "yes":

          // Do something

          Break;

    Case "no":

          // Fall through to next block

    Default:

          // Do something

          Break;

End;

 

 

Details


The "Case" must be a literal number or string and must evaluate to an integer. Variable or String objects cannot be used, to prevent conflicts in which the evaluation of the Case changes the value of the Variable or String in question.

If the Switch input argument evaluates to one of the cases, that Case is executed.

If the Switch input argument does not evaluate to any of the Cases, the Default is executed.

A Break statement stops the evaluation of all following Cases (including the Default) and exits the Switch block entirely.

Note that a colon (:) is used after each Case and Default statement, instead of a semicolon (;).

The Break statement can also be used to exit a While or a For loop without completing any remaining iterations of the loop or executing any remaining commands within the loop.

 

Examples


Use Switch to determine what type of output will be generated

 

Use Switch to determine whether to generate output Ephemeris file

 

Use Switch to maneuver a Spacecraft

 

 

See Also


If Statement