Note: test should almost always be enclosed in braces. If not, variable substitutions will be made before the while command starts executing, which means that variable changes made by the loop body will not be considered in the expression. This is likely to result in an infinite loop. If test is enclosed in braces, variable substitutions are delayed until the expression is evaluated (before each loop iteration), so changes in the variables will be visible. For an example, try the following script with and without the braces around $x<10:
set x 0 while {$x<10} { puts "x is $x" incr x }
set lineCount 0 while {[gets $chan line] >= 0} { puts "[incr lineCount]: $line" }
Copyright © 1993 The Regents of the University of California.
Copyright © 1994-1997 Sun Microsystems, Inc.
Licensed under Tcl/Tk terms
https://www.tcl.tk/man/tcl/TclCmd/while.htm