for.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
- '"
- '" Copyright (c) 1993 The Regents of the University of California.
- '" Copyright (c) 1994-1997 Sun Microsystems, Inc.
- '"
- '" See the file "license.terms" for information on usage and redistribution
- '" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
- '"
- '" RCS: @(#) $Id: for.n,v 1.3.18.1 2004/10/27 12:52:40 dkf Exp $
- '"
- .so man.macros
- .TH for n "" Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- for - ``For'' loop
- .SH SYNOPSIS
- fBfor fIstart test next bodyfR
- .BE
- .SH DESCRIPTION
- .PP
- fBForfR is a looping command, similar in structure to the C
- fBforfR statement. The fIstartfR, fInextfR, and
- fIbodyfR arguments must be Tcl command strings, and fItestfR
- is an expression string.
- The fBforfR command first invokes the Tcl interpreter to
- execute fIstartfR. Then it repeatedly evaluates fItestfR as
- an expression; if the result is non-zero it invokes the Tcl
- interpreter on fIbodyfR, then invokes the Tcl interpreter on fInextfR,
- then repeats the loop. The command terminates when fItestfR evaluates
- to 0. If a fBcontinuefR command is invoked within fIbodyfR then
- any remaining commands in the current execution of fIbodyfR are skipped;
- processing continues by invoking the Tcl interpreter on fInextfR, then
- evaluating fItestfR, and so on. If a fBbreakfR command is invoked
- within fIbodyfR
- or fInextfR,
- then the fBforfR command will
- return immediately.
- The operation of fBbreakfR and fBcontinuefR are similar to the
- corresponding statements in C.
- fBForfR returns an empty string.
- .PP
- Note: fItestfR should almost always be enclosed in braces. If not,
- variable substitutions will be made before the fBforfR
- 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 fItestfR 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.
- See below for an example:
- .SH EXAMPLES
- Print a line for each of the integers from 0 to 10:
- .CS
- for {set x 0} {$x<10} {incr x} {
- puts "x is $x"
- }
- .CE
- .PP
- Either loop infinitely or not at all because the expression being
- evaluated is actually the constant, or even generate an error! The
- actual behaviour will depend on whether the variable fIxfR exists
- before the fBforfR command is run and whether its value is a value
- that is less than or greater than/equal to ten, and this is because
- the expression will be substituted before the fBforfR command is
- executed.
- .CS
- for {set x 0} $x<10 {incr x} {
- puts "x is $x"
- }
- .CE
- .PP
- Print out the powers of two from 1 to 1024:
- .CS
- for {set x 1} {$x<=1024} {set x [expr {$x * 2}]} {
- puts "x is $x"
- }
- .CE
- .SH "SEE ALSO"
- break, continue, foreach, while
- .SH KEYWORDS
- for, iteration, looping