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
whilestatements must terminate with theendkeyword.
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:
- Checks if
n > 0(initially5). - Appends
ntoresultand decrementsn. - Repeats until
nequals0.