Skip to main content
Loops let you execute a block of code repeatedly without duplicating it. Standard provides two loop constructs: the for loop for iterating over a sequence or a set number of steps, and the while loop for repeating code as long as a condition remains true. Both are concise to write and easy to read.

The For Loop

The for loop runs a block of code until it reaches the end of a given sequence. In Standard, that sequence can be a single integer — causing the block to execute that exact number of times — or an array of objects to iterate over. Use @ inside the loop body to reference the current working object. Print the loop index five times:
Iterate through database results:

The While Loop

The while loop runs a block of code repeatedly until the condition you provide evaluates to false. Make sure the condition can eventually become false to avoid an infinite loop.
Always ensure the condition in a while loop will eventually evaluate to false. If the condition never changes, your program will loop indefinitely and become unresponsive.