Navigation: Interface Design Concepts > Instructions >

ForLoop

 

 

 

 

The for-loop, or forLoop, can be used to repeat statements a certain number of times and to count. As MPJ is a single-line processing environment, the for-loop and the statements need to exist on a single line. The value of the count can be accessed by using the ampersand (&) where you want to use the value.  Negative values for step size should not be used. forLoop uses integers only.

 

The structure of the forLoop is:

!forLoop startValue, endValue, stepSize: statements using & for the count value if desired.

 

!forLoop 0,10,1:? &  //counts from 0 to 10 by 1 displaying the values

 

!forLoop 10,0,1: ? &    // counts from 10 to 0 by 1 displaying the value.

 

The value pointer, &, may be used for indexing of controls or variables, such as for txtValue 0 to 9 as controls.
 

!makeVar varSum=0
!forLoop 0,9,1: !varSum = { [varSum] + [txtValue&] }

? { [varSum] / 10 }

 

forLoopFP is a floating point version of the for-Loop. As it does have issues with rounding error (e.g.: 0.5 + 0.2 = 0.7000001), it is recommended to use the format instruction in post-fix math to set the number of decimals for some operations. Note that counting from 1 to 10 results in trailing 0: 1.0, 2.0, 3.0, etc, so it is not recommended for use where the integer value is needed, such as in control or indexed variable names.
 

!forLoopFP 0.5, 10.2, 0.2: ? &

!forLoopFP 0.5, 10.2, 0.2: ? {:: & %.2f format }

 

 

 

 

 

Copyright © 2024 SelmaWare Solutions, LLC