Node:Truncation, Next:Enumerations, Previous:Selection, Up:Sequences
Q while B | Function |
The while operation is used to select the initial elements
of a sequence, but leaving out the first element that fails to satisfy
a condition, as well as all subsequent elements.
Truncates Q from with the first element (inclusive)
that fails the condition B.
See the usage of |
Q until B | Function |
Similar as while , but with the condition negated:
Truncate Q leaving out all elements after
the first element that does satisfy B.
Note that the first element (only) that satisfies B
is included in the output.
|
Note that while
can be used in place of the while
loops
in many programming languages:
{expr1} while {expr2} do
corresponds exactly to C's:
while (expr2) { expr1; }
Similarly, until
is like the repeat ... until
or
do .. until
of many programming languages:
{expr1} until {expr2} do
corresponds exactly to C's:
do { expr1; } until (expr2);
Q2> [3 4 5 -4 8 -1 10] while (> 0) 3 4 5 Q3> [3 4 5 -4 8 -1 10] until (> 0) 3 Q4> [3 4 5 -4 8 -1 10] until (<= 0) 3 4 5 -4