while, until

Synopsis:
while (<condition>) <action>
while (<condition) [{ <action> }]

Description:
The while loop is a sort of hybrid between the for loop and the if control statement. It allows for repetitive action, as with for, but the loop iterates (performs the action) only if a specific condition is met, as with if. The "condition" portion may contain any comparison or assignment allowed in an if statement.

Examples:
To display a warning message 3 times:
@ xx = 3
while ( xx > 0 ) {
..echo WARNING! This ship will self destruct in $xx seconds!
..@ xx--
}

A infinite loop that behaves like the Unix 'yes' command:
while ( 1 ) echo yes

Aliases:
until is the exact opposite of while. It is essentially the same applying the negation operator (!) to the entire while condition.

See Also:
fe, fec
for
foreach

Other Notes:
while has all of the capabilities of for, only in a different syntax. The distinction between the two is not great enough to warrant a recommendation of one over the other. If anything, for tends to be more concise than while; however, this is not always the case.

 

Back

Hosted by www.Geocities.ws

1