Patron Wiki

When you need a certain block of code to run numerous times in a sequence, use the For loop.

Here's an example:

int i = 0 ;
int stopValue = 10 ;

for i = 0 < stopValue step 1
  PrintMessageVar RUNNING_LOOP: INT i ;
endfor

The above does the following:

  • start "i" at the value of 0
  • check if it is lower than "stopValue"
  • if it is, print the message
  • increment "i" by step (1)
  • run the loop again and again until "i" is no longer lower than "stopValue"
  • when this happens, proceed executing the script following "endfor"

Looping through an array[]

A pretty common task is looping through the contents of an array, so we'll cover it here as well:

int i = 0 ;
int var = 0 ;
int iMax = 0 ;
array GetElementNum arrayName iMax ;
for i = 0 < iMax step 1
  array Get arrayName var i ;
  PrintMessageVar VALUE_IN_ARRAY: INT var ;
endfor