2 '\" Copyright (c) 1993 The Regents of the University of California.
3 '\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
5 '\" See the file "license.terms" for information on usage and redistribution
6 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11 .TH for n "" Tcl "Tcl Built-In Commands"
13 '\" Note: do not modify the .SH NAME line immediately below!
17 \fBfor \fIstart test next body\fR
22 \fBFor\fR is a looping command, similar in structure to the C
23 \fBfor\fR statement. The \fIstart\fR, \fInext\fR, and
24 \fIbody\fR arguments must be Tcl command strings, and \fItest\fR
25 is an expression string.
26 The \fBfor\fR command first invokes the Tcl interpreter to
27 execute \fIstart\fR. Then it repeatedly evaluates \fItest\fR as
28 an expression; if the result is non-zero it invokes the Tcl
29 interpreter on \fIbody\fR, then invokes the Tcl interpreter on \fInext\fR,
30 then repeats the loop. The command terminates when \fItest\fR evaluates
31 to 0. If a \fBcontinue\fR command is invoked within \fIbody\fR then
32 any remaining commands in the current execution of \fIbody\fR are skipped;
33 processing continues by invoking the Tcl interpreter on \fInext\fR, then
34 evaluating \fItest\fR, and so on. If a \fBbreak\fR command is invoked
37 then the \fBfor\fR command will
39 The operation of \fBbreak\fR and \fBcontinue\fR are similar to the
40 corresponding statements in C.
41 \fBFor\fR returns an empty string.
43 Note: \fItest\fR should almost always be enclosed in braces. If not,
44 variable substitutions will be made before the \fBfor\fR
45 command starts executing, which means that variable changes
46 made by the loop body will not be considered in the expression.
47 This is likely to result in an infinite loop. If \fItest\fR is
48 enclosed in braces, variable substitutions are delayed until the
49 expression is evaluated (before
50 each loop iteration), so changes in the variables will be visible.
51 For an example, try the following script with and without the braces
54 for {set x 0} {$x<10} {incr x} {
60 for, iteration, looping