Do
rascal-0.40.17
Synopsis
Repeat statements while condition holds.
Syntax
do
Statement
while (Exp);
do {
Statements
} while (Exp);
Description
Statement is executed repeatedly, as long as the Boolean expression Exp yields true. Expression Exp is executed from scratch in each repetition and only the first true value (if any) is used.
By default, the value of a do statement is the empty list. In general, the value of a do statement consists of all values contributed by Append statements that are executed during the repeated execution of its body Statement.
Examples
rascal>import IO;
ok
rascal>int n = 3;
int: 3
rascal>do { println("n = <n>"); n -= 1; } while (n > 0);
n = 3
n = 2
n = 1
list[void]: []
Now build a list result using the append
statement:
rascal>n = 3;
int: 3
rascal>do { append n * n; n -= 1; } while (n > 0);
list[int]: [9,4,1]