![]() ![]() ![]() ![]() | Table Of Contents | Index |
Example:You start with LOOP (Number) which specifies the number of times to execute the code between LOOP and ENDLOOP. There are 2 variables available here for loop control. LoopIndex starts at 1 and is incremented at each EndLoop. When LoopIndex becomes greater than LoopLimit, the loop exits. LoopIndex and LoopLimit refer to the innermost loop.
Loop 8 Writeln 'Pass Number ' LoopIndex EndLoop
As loops are nested, LoopIndexes and LoopLimits are kept in two arrays; LoopIndexStack and LoopLimitStack. There is also a variable called LoopLevel which points to the current loop parameters.
Thus: LoopIndex is the same as LoopIndexStack[LoopLevel] LoopLimit is the same as LoopLimitStack[LoopLevel]You may therefore access outer loop parameters through the loop stacks. For instance LoopIndexStack[LoopLevel - 1] would refer to the second innermost loop index. LoopIndexStack[1] refers to the outermost loop.
The loop variables can be read and written so that you can adjust the looping parameters while inside the loop. You can even adjust the parameters of outer loops.
You can also pass an array to a loop instead of a number. If an array is passed MarxMenu will loop for the number of elements in that array.
Example:You can specify a start and end of the loop:
Var X ReadTextFile('MARXREAD.ME',X) OpenPrinter;Loop X is the same as Loop NumberOfElements X
Loop X PrintLn LoopVal EndLoop ClosePrinter
Example:This will loop starting at 5 and ending at 10. If you also specify an array variable, you can loop through a section of the array.
Loop 5 10 Writeln LoopIndex EndLoop
Example:In the above example, MarxMenu will write out the loop values for elements 3 thru 9 of MyArray.
Loop 3 9 MyArray Writeln LoopVal EndLoop
See Also: | EndLoop | LoopIndex | LoopLimit | LoopLevel | LoopVal |
---|
Category: | Conditional | Array |
---|
![]() ![]() ![]() ![]() | Table Of Contents | Index |
|