Note: information on this page refers to Ceylon 1.0, not to the current release.
while statement
The while statement executes a block of code repeatedly.
Usage
The general form of the while statement is:
while ( /* condition */ ) {
/* while block */
}
/* code after while statement */
Description
Execution
A while statement executes a block of code repeatedly until the
while condition evaluates to false (or the block is exited via
a return, throw or break directive).
break and continue
Within the while block the break directive can be
used to exit the block early without waiting for the condition to
become false.
The continue directive can be used to skip
execution of the remainder of the block.
Conditions
The conditions in a while statement form a
condition list.
Any expression of type Boolean
may be occur in the condition list of a while statement. The
while statement also supports the use of typing conditions:
These conditions narrow the type of a reference within the while
block, and in later conditions in the condition list.
Object takeNext() {
// ...
}
void takeSmallIntegers() {
while (is Integer x=takeNext(), x < 10) {
// ...
}
}
Notes
- Ceylon has no
do/whilestatement as seen in other C-like languages.
See also
- The
breakstatement - The
continuestatement - The
forstatement - The
whilestatement in the Tour of Ceylon - The
whilestatement in the language specification