Switch |
Top Previous Next |
DescriptionThe 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
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
|
Ephemeris Ephemeris1;
// User sets a: Variable a = 1;
While (Spacecraft1.ElapsedTime < TIMESPAN(1 days));
// Determine output type Switch (a); Case 0: // Do nothing Break; Case 1: Plot Spacecraft1.ElapsedTime, Spacecraft1.A; Break; Case 2: Report Spacecraft1.ElapsedTime, Spacecraft1.A; Break; Case 3: Put Spacecraft1 to Ephemeris1; Break; Default: Watch Spacecraft1.A; Break; End;
View Spacecraft1; Step Spacecraft1; End; |
Use Switch to determine whether to generate output Ephemeris file
Switch (a); Case 3: Put Ephemeris1 to FFephem "SwitchEphem.FFephem"; Break; Default: // Do nothing Break; End; |
Use Switch to maneuver a Spacecraft
// Create Burn ImpulsiveBurn ImpulsiveBurn1; ImpulsiveBurn1.AttitudeSystem = 1; ImpulsiveBurn1.BurnDirection[0] = 0.1;
// Propagate and Maneuver Spacecraft While (Spacecraft1.ElapsedTime < 1);
Switch (Spacecraft1.ElapsedTime.ToHours());
Case 1: Maneuver Spacecraft1 using ImpulsiveBurn1; Step Spacecraft1; Break;
Case 3: Maneuver Spacecraft1 using ImpulsiveBurn1; Step Spacecraft1; Break;
Case 4: // Fall through to next block
Default: Step Spacecraft1; Break; End; End; |
•If Statement