Seth Woolley's Man Viewer

for(n) - for, for - ``For'' loop - man n for

([section] manual, -k keyword, -K [section] search, -f whatis)
man plain no title

for(n)                       Tcl Built-In Commands                      for(n)



NAME
       for - ``For'' loop

SYNOPSIS
       for start test next body


DESCRIPTION
       For  is a looping command, similar in(1,8) structure to the C for statement.
       The start, next, and body arguments must be Tcl  command  strings,  and
       test  is  an  expression string.  The for command first invokes the Tcl
       interpreter to execute start.  Then it repeatedly evaluates test as  an
       expression; if(3,n) the result is non-zero it invokes the Tcl interpreter on
       body, then invokes the Tcl interpreter on next, then repeats the  loop.
       The command terminates when test evaluates to 0.  If a continue command
       is invoked within body then any remaining commands in(1,8) the current  exe-
       cution  of  body  are skipped; processing continues by invoking the Tcl
       interpreter on next, then evaluating test, and so on.  If a break  com-
       mand  is  invoked within body or next, then the for command will return
       immediately.  The operation of break and continue are  similar  to  the
       corresponding statements in(1,8) C.  For returns an empty string.

       Note:  test  should almost always be enclosed in(1,8) braces.  If not, vari-
       able substitutions will be made before the for command  starts  execut-
       ing,  which  means that variable changes made by the loop body will not
       be considered in(1,8) the expression.  This is likely to result in(1,8) an  infi-
       nite  loop.   If test is enclosed in(1,8) braces, variable substitutions are
       delayed until the expression is evaluated (before each loop iteration),
       so  changes  in(1,8) the variables will be visible.  For an example, try the
       following script with and without the braces around $x<10: for  {set(7,n,1 builtins)  x
       0} {$x<10} {incr x} {      puts(3,n) "x is $x" }


SEE ALSO
       break, continue, foreach, while


KEYWORDS
       for, iteration, looping



Tcl                                                                     for(n)

References for this manual (incoming links)