while

while statements repeatedly executes a block of statements as long as a boolean condition evaluates to true.

Syntax

while <condition> do 
   <statements> 
end
condition
A Boolean expression evaluated before each iteration.
statements
The code block executed when condition is true.
end
All while statements must terminate with the end keyword.

Example

The following example counts down from 5 to 1:

declare 'n' being 5;

while n is more than 0 do 
    set result to result + n + " ";
    set n to n - 1;
end

// Output: "5 4 3 2 1 "
It works as follows:
  1. Checks if n > 0 (initially 5).
  2. Appends n to result and decrements n.
  3. Repeats until n equals 0.