If

Top  Previous  Next

Description


The If statement contains a block of commands that execute if an expression is evaluated to be true. The If statement always concludes with an End statement. For more information, see the Flow Control Script Reference.

 

 

Syntax


Generic Use Cases
 

If (mySpacecraft.Height < 100);
    Stop;
End;
 
If (myVariable);

    // Executes if myVariable = 1 (true)
    Plot mySpacecraft.ElapsedTime, mySpacecraft.Height;
End;

 

Using Else and ElseIf

 

If (Variable1 > 5);

    // ...

ElseIf (Variable2 == Variable3);

    // ...

Else;

    // ...

End;

 

 

Details


It is possible to test for multiple logical conditions using the "and" and "or" operators. See the Flow Control Script Reference for more information.

 

An If statement can depend on an unlimited number of conditional statements. Possible relational conditions are:

o<, <=, >, >=, ==, !=, IsType

 

When the syntax "If (myVariable);" is used, the expression is:

oFalse, if myVariable equals zero.

oTrue, if myVariable does not equal zero.

 

The ElseIf statement can be used to specify alternative conditional statements.

oMultiple ElseIf statements may be used within a single If block.

 

The Else statement can be used to define a block of commands that execute when the If statement and any ElseIf statements are all evaluated to be false.

 

An If statement must be closed with an End statement.

 

To create complex logic flow, you can construct nested loops using multiple If commands, along with For and While statements.

 

Additional conditional syntax supported in millisecond timing precision mode only:

ois, not, very, somewhat, almost, usually (used with FuzzySet object only)

o= (equivalent to ==)

o~= (equivalent to !=)

 

The "then" keyword is optional following the conditional portion of an If statement.

 

 

Command Editor


Left side of expression

Defines the object, property, or method that is evaluated to determine whether loop contents will be executed

oArray element

oObject

oObject property/method

 

Evaluation Type

 

Evaluation

Definition

==

Equal to

>=

Greater than or equal to

<

Less than

!=

Not equal to

~=

Not equal to

>

Greater than

<=

Less than or equal to

 

Right side of expression

Defines the value that the left side of the expression will be tested against

 

Script

Displays the FreeFlyer Script that is generated by the editor

The ellipsis (...) indicates that additional script can be added inside the loop

 

Description

Displays descriptions of the editor and its fields

Description text changes as the mouse pointer moves over the different fields within the editor

 

 

 

Examples


Generic Examples
 

If (mySpacecraft.Height < 100 and mySpacecraft.ElapsedTime >= TIMESPAN(2 days));
    Plot mySpacecraft.ElapsedTime, mySpacecraft.Height;
End;
 

// Report "Spacecraft in contact!" if two Spacecraft are in contact

If (Spacecraft1.Contact(Spacecraft2));
    Report "Spacecraft in contact!" to "Contact.Report";
End;

 

Using Else and ElseIf

 

If (mySpacecraft.Height < 100);
    Stop;
Else;
    Plot mySpacecraft.ElapsedTime, mySpacecraft.Height;
End;

 

// Use the Else statement to provide two possible reports

If (Spacecraft1.Contact(Spacecraft2));
    Report "Spacecraft in contact!" to "Contact.Report";
Else;
    Report "No contact" to "Contact.Report";
End;

 

 

See Also


Type Casting

Flow Control Script Reference