1while(n)                     Tcl Built-In Commands                    while(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       while - Execute script repeatedly as long as a condition is met
9

SYNOPSIS

11       while test body
12______________________________________________________________________________
13

DESCRIPTION

15       The while command evaluates test as an expression (in the same way that
16       expr evaluates its argument).  The  value  of  the  expression  must  a
17       proper  boolean  value;  if it is a true value then body is executed by
18       passing it to the Tcl interpreter.  Once body has  been  executed  then
19       test  is evaluated again, and the process repeats until eventually test
20       evaluates to a false boolean value.  Continue commands may be  executed
21       inside  body  to terminate the current iteration of the loop, and break
22       commands may be executed inside body to cause immediate termination  of
23       the while command.  The while command always returns an empty string.
24
25       Note:  test  should almost always be enclosed in braces.  If not, vari‐
26       able substitutions will be made before the while command starts execut‐
27       ing,  which  means that variable changes made by the loop body will not
28       be considered in the expression.  This is likely to result in an  infi‐
29       nite  loop.   If test is enclosed in braces, variable substitutions are
30       delayed until the expression is evaluated (before each loop iteration),
31       so  changes  in the variables will be visible.  For an example, try the
32       following script with and without the braces around $x<10:
33
34              set x 0
35              while {$x<10} {
36                  puts "x is $x"
37                  incr x
38              }
39

EXAMPLE

41       Read lines from a channel until we get to the end of  the  stream,  and
42       print them out with a line-number prepended:
43
44              set lineCount 0
45              while {[gets $chan line] >= 0} {
46                  puts "[incr lineCount]: $line"
47              }
48

SEE ALSO

50       break(n), continue(n), for(n), foreach(n)
51

KEYWORDS

53       boolean, loop, test, while
54
55
56
57Tcl                                                                   while(n)
Impressum