Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

A loop statement allows us to execute a block of code multiple times.

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 the following example clearly in the Translator by navigating the loops in the Annotation Windows.

  • No labels