Synopsis While loop.
Syntax while ( Exp ) Statement;
Description The Boolean expression Exp is evaluated repeatedly and Statement is executed when the test is true. Execution ends the first time that the test yields false. The test Exp is executed from scratch in each repetition and only the first true value (if any) is used. This is relevant when Exp contains a Match or NoMatch operator.

By default, the value of a while statement is the empty list. In general, the value of a while statement consists of all values contributed by Append statements that are executed during the repeated execution of its body Statement.
rascal>import IO;
rascal>int n = 3;
int: 3
rascal>while( n > 0 ) { println("n = <n>"); n -= 1; }
n = 3
n = 2
n = 1
list[void]: []
Now build a list result using the append statement:
rascal>n = 3;
int: 3
rascal>while (n > 0) { append n * n; n -= 1; }
list[int]: [9,4,1]
Just to be sure, a List/Comprehension is the superior way to write this:
rascal>[n * n | n <- [3 .. 1]];
list[int]: [9,4]
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit