For

Top  Previous  Next

Description


The For statement contains a block of commands that are executed as a property is increased or decreased until it reaches a terminating condition. The initial and final values of the property are specified, as well as the incremental step value. The For statement always concludes with an End statement. For more information, see the Flow Control Script Reference.

 

 

Syntax


For myVariable = 1 to 10; // This assumes an increment of 1 through the loop

      Report myArray[myVariable];

End;

 

For myVariable = 1 to -10 step -1// This specifies an increment of -1 to decrease the value through the loop

      Report myVariable;

End;

 

For myVariable = 1 to 10 step 2;
    Report myArray[myVariable];
End;
 
For mySpacecraft.A = 7000 to 8000 step myVariable;
    Report mySpacecraft.A;
End;

 

For myTimeSpan = TS(0 daysto TS(2 daysstep TS(60 seconds);

    Report mySpacecraft.A;

End;

 

For Variable1 = 1 to 10 step 2 with reset;

    Step Spacecraft1;

    Report Spacecraft1.ElapsedTime;

End;

 

 

Details


All commands between For and End are executed for each increment or decrement of the property.

The "step" keyword is used with the For command to specify the increment size; this can be positive, negative, or omitted entirely for the loop to assume an increment of +1. If the iterator is a TimeSpan value, the assumed increment is +1 day.

The fourth example shown above will increment mySpacecraft.A by myVariable, beginning at 7000 and ending at 8000.

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

The Break and Continue statements can be used to control logic flow for exiting For loops.

In nanosecond timing precision mode, properties and methods with a state are not reset at the start of each iteration of a For loop.

oThe "with reset" keywords can be used to force these properties and methods to reset their state at the start of each iteration of a For loop as shown in the fifth example above.

In millisecond timing precision mode, properties and methods with a state are automatically reset at the start of each iteration of a For loop.

oThe "without reset" keywords can be used to prevent the state from being reset.

 

 

Command Editor


Value to Change

Defines the item that will be incremented

This can be an:

oArray element

oVariable

oObject property

 

Initial Value

Defines the starting point for the For loop

 

Finished Value

Defines the termination point for the For loop

 

Increment

Defines the step increment for the For loop

 

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

 

 

 

See Also


If

While

Continue

Break

Flow Control Script Reference

Properties and Methods with a State