Loop

Prev Next Home Home Table Of Contents Index

Loop

MarxMenu has a looping structure that lets you execute a piece of code a specific number of times. It is used as follows:


Example:
Loop 8 Writeln 'Pass Number ' LoopIndex EndLoop

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.

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:
Var X ReadTextFile('MARXREAD.ME',X) OpenPrinter

;Loop X is the same as Loop NumberOfElements X

Loop X PrintLn LoopVal EndLoop ClosePrinter

You can specify a start and end of the loop:


Example:
Loop 5 10 Writeln LoopIndex EndLoop

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.


Example:
Loop 3 9 MyArray Writeln LoopVal EndLoop

In the above example, MarxMenu will write out the loop values for elements 3 thru 9 of MyArray.

See Also: EndLoop LoopIndex LoopLimit LoopLevel LoopVal

Category: Conditional Array

Prev Next Home Home Table Of Contents Index

Sponsors
Shopping
Forum
Forum
email
EMail
Index
Index
Home
Home