Description
Repeats processing as long as a condition is met.
Synopsis
while {test} {body}
Options
Specify the conditional expression that repeats a loop (body). For a numeric value, 0 is false and anything other than 0 is true. For a string value, true and yes are true and false and no are false. Do not put a comment into conditional expression.
! | NOT |
< , > , <= , >= , == , != | Comparison |
&& , || | Logical AND, Logical OR |
The script command executed as long as the condition is true. Two or more commands can be written by being separated by line breaks or semicolons.
Cautions
"while" must be separated from "{}" by blanks or tabs. "}" in the conditional expression must be separated from "{" in the body must be separated by blanks or tabs.
When inserting a line break in other than body such as between "}" and "{", add a backslash sign to the end of the line to indicate continuation.
A while statement involving an error in the conditional evaluation logic may result in an infinite loop. To avoid this, it is recommend that a protective mechanism as described below be provided so as to prevent the loop being executed over a certain time.
Provide a while statement with a variable for the counter that is not used in any other elements in the statement and have that value checked at an early stage in that while statement for each iteration of a loop.
Example
The following example executes a loop five times.
set i 0 while {$i < 5} { incr i }