1mNAME0m
       for - ``For'' loop

1mSYNOPSIS0m
       1mfor 4m22mstart24m 4mtest24m 4mnext24m 4mbody0m


1mDESCRIPTION0m
       1mFor  22mis a looping command, similar in structure to the C 1mfor 22mstatement.
       The 4mstart24m, 4mnext24m, and 4mbody24m arguments must be Tcl  command  strings,  and
       4mtest24m  is  an  expression string.  The 1mfor 22mcommand first invokes the Tcl
       interpreter to execute 4mstart24m.  Then it repeatedly evaluates 4mtest24m as  an
       expression; if the result is non-zero it invokes the Tcl interpreter on
       4mbody24m, then invokes the Tcl interpreter on 4mnext24m, then repeats the  loop.
       The command terminates when 4mtest24m evaluates to 0.  If a 1mcontinue 22mcommand
       is invoked within 4mbody24m then any remaining commands in the current  exe-
       cution  of  4mbody24m  are skipped; processing continues by invoking the Tcl
       interpreter on 4mnext24m, then evaluating 4mtest24m, and so on.  If a 1mbreak  22mcom-
       mand  is  invoked within 4mbody24m or 4mnext24m, then the 1mfor 22mcommand will return
       immediately.  The operation of 1mbreak 22mand 1mcontinue 22mare  similar  to  the
       corresponding statements in C.  1mFor 22mreturns an empty string.

       Note:  4mtest24m  should almost always be enclosed in braces.  If not, vari-
       able substitutions will be made before the 1mfor 22mcommand  starts  execut-
       ing,  which  means that variable changes made by the loop body will not
       be considered in the expression.  This is likely to result in an  infi-
       nite  loop.   If 4mtest24m 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 1m$x<1022m:
              for {set x 0} {$x<10} {incr x} {
                puts "x is $x"
              }


1mSEE ALSO0m
       break, continue, foreach, while


1mKEYWORDS0m
