Use the for loop as a counting loop.

The for loop has a start value, an end value, and an increment or decrement value.

Every for loop must end with an endfor.

The syntax is:

for variable = start value, target value, increment
      // Code
endfor
  • Separate the start value, target value, and increment using a comma.
  • The start value, target value and increment must be integers (int32).
  • The increment is optional. If you do not specify an increment, its value is 1.
  • You cannot change the increment within the body of the loop.
  • You can create a decrementing loop with a negative increment value.
  • You can exit the loop prematurely with break.

Example: for Loop

program
 int32 i
 int32 k = 11
 for i = 1, k, 2
   sys:logInfo(sys:ui, "i = %d", i)
 endfor
endprogram