Declares the start of a For/Next loop.
For Local IndexVar := start_value To end_value [ Step constant_value ]
Statements...
Next
For Local IndexVar := start_value Until end_value [ Step constant_value ]
Statements...
Next
For Local IndexVar := Eachin value_set
Statements...
Next
For declares the start of a For/Next loop, allowing for iteration through a set of values or objects.
There are three variants of the For/Next loop, modifying the values of the index variable via the range keywords below:
To: Iterates through the given start and end values;Until: This variant of For/Next stops iterating before the last value in the loop, useful for iterating through zero-based arrays. (See Example 3.)Eachin: Iterates through a set of objects or values, such as a list or array;
Alternatives to the closing Next keyword are End For, or simply End.
For k=1 To 1000 Print kNext' With optional StepFor k=1 To 1000 Step 100 Print kNext' Alternative syntax examplesFor k=1 To 1000 Print kEndFor k=1 To 1000 Print kEnd For
' Assume m:MyObject and mylist:ListFor m=Eachin mylist Print m.myFieldNext' Assume i:Int and myarray:Int[]For i=Eachin myarray Print myarray[i]Next
NUM = 100 ' Assume myarray[NUM] has been declared' Prints 0 to 99 without requiring NUM-1For k=0 Until NUM Print myarray[k]Next