while.n
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:2k
- '"
- '" 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: while.n,v 1.3.18.1 2004/10/27 14:43:15 dkf Exp $
- '"
- .so man.macros
- .TH while n "" Tcl "Tcl Built-In Commands"
- .BS
- '" Note: do not modify the .SH NAME line immediately below!
- .SH NAME
- while - Execute script repeatedly as long as a condition is met
- .SH SYNOPSIS
- fBwhile fItest bodyfR
- .BE
- .SH DESCRIPTION
- .PP
- The fBwhilefR command evaluates fItestfR as an expression
- (in the same way that fBexprfR evaluates its argument).
- The value of the expression must a proper boolean
- value; if it is a true value
- then fIbodyfR is executed by passing it to the Tcl interpreter.
- Once fIbodyfR has been executed then fItestfR is evaluated
- again, and the process repeats until eventually fItestfR
- evaluates to a false boolean value. fBContinuefR
- commands may be executed inside fIbodyfR to terminate the current
- iteration of the loop, and fBbreakfR
- commands may be executed inside fIbodyfR to cause immediate
- termination of the fBwhilefR command. The fBwhilefR command
- always returns an empty string.
- .PP
- Note: fItestfR should almost always be enclosed in braces. If not,
- variable substitutions will be made before the fBwhilefR
- 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.
- For an example, try the following script with and without the braces
- around fB$x<10fR:
- .CS
- set x 0
- fBwhilefR {$x<10} {
- puts "x is $x"
- incr x
- }
- .CE
- .SH EXAMPLE
- Read lines from a channel until we get to the end of the stream, and
- print them out with a line-number prepended:
- .CS
- set lineCount 0
- fBwhilefR {[gets $chan line] >= 0} {
- puts "[incr lineCount]: $line"
- }
- .CE
- .SH "SEE ALSO"
- break(n), continue(n), for(n), foreach(n)
- .SH KEYWORDS
- boolean value, loop, test, while