Next: The For Statement, Previous: The If Statement, Up: Expressions And Statements [Index]
The two statements provide for cyclic code execution. The ‘while’ statement executes a block for as long as an initial condition passes. The ‘do’ ‘while’ executes the block until a final condition fails.
The syntax of the ‘while’ statement is similar to that of the simple ‘if’ statement, with the ‘while’ keyword replacing the ‘if’.
integer a; a = 0; while (a < 16) { o_space(1); o_integer(a); a += 1; }
The fragment prints:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The condition is enclosed by parantheses and following the ‘while’ keyword.
The syntax of the ‘do’ ‘while’ statement has the condition placed after the block to execute and a final semicolon completing it.
integer a; a = 32; do { a -= 1; o_space(1); o_integer(a); } while (16 < a);
The fragment prints:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Like for the ‘if’ statement, the evaluated expression should result in data of one of the numerical intrinsic types, or to ‘object’ data encasing data of the former types.