for loop

A for loop allows you to execute a block of code a specific number of times.

for init, max/min value, increment/decrement do trace("executed code") end
  • init or i: initialization variable or a starting value

  • max/min value: maximum or minimum value till which the loop continues to execute.

  • increment/decrement: a counter defined to update the value after each iteration fo the loop. By default, this value is defined as 1 if not specified.

For example: The for loop below defines i to start at 1 and loop through the statement, until i=5, incrementing by 1 each time.

for i = 1, 5 do trace("Iteration: "..i) end

We can see this example clearly in the Translator by navigating the loops in the Annotation Windows and seeing the iteration count change.

 

Related pages