Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/tcl8.5.2/doc/while.n @ 37

Last change on this file since 37 was 25, checked in by landauf, 16 years ago

added tcl to libs

File size: 2.2 KB
Line 
1'\"
2'\" Copyright (c) 1993 The Regents of the University of California.
3'\" Copyright (c) 1994-1997 Sun Microsystems, Inc.
4'\"
5'\" See the file "license.terms" for information on usage and redistribution
6'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
7'\"
8'\" RCS: @(#) $Id: while.n,v 1.5 2004/10/27 14:43:54 dkf Exp $
9'\"
10.so man.macros
11.TH while n "" Tcl "Tcl Built-In Commands"
12.BS
13'\" Note:  do not modify the .SH NAME line immediately below!
14.SH NAME
15while \- Execute script repeatedly as long as a condition is met
16.SH SYNOPSIS
17\fBwhile \fItest body\fR
18.BE
19
20.SH DESCRIPTION
21.PP
22The \fBwhile\fR command evaluates \fItest\fR as an expression
23(in the same way that \fBexpr\fR evaluates its argument).
24The value of the expression must a proper boolean
25value; if it is a true value
26then \fIbody\fR is executed by passing it to the Tcl interpreter.
27Once \fIbody\fR has been executed then \fItest\fR is evaluated
28again, and the process repeats until eventually \fItest\fR
29evaluates to a false boolean value.  \fBContinue\fR
30commands may be executed inside \fIbody\fR to terminate the current
31iteration of the loop, and \fBbreak\fR
32commands may be executed inside \fIbody\fR to cause immediate
33termination of the \fBwhile\fR command.  The \fBwhile\fR command
34always returns an empty string.
35.PP
36Note: \fItest\fR should almost always be enclosed in braces.  If not,
37variable substitutions will be made before the \fBwhile\fR
38command starts executing, which means that variable changes
39made by the loop body will not be considered in the expression.
40This is likely to result in an infinite loop.  If \fItest\fR is
41enclosed in braces, variable substitutions are delayed until the
42expression is evaluated (before
43each loop iteration), so changes in the variables will be visible.
44For an example, try the following script with and without the braces
45around \fB$x<10\fR:
46.CS
47set x 0
48\fBwhile\fR {$x<10} {
49    puts "x is $x"
50    incr x
51}
52.CE
53.SH EXAMPLE
54Read lines from a channel until we get to the end of the stream, and
55print them out with a line-number prepended:
56.CS
57set lineCount 0
58\fBwhile\fR {[gets $chan line] >= 0} {
59    puts "[incr lineCount]: $line"
60}
61.CE
62
63.SH "SEE ALSO"
64break(n), continue(n), for(n), foreach(n)
65
66.SH KEYWORDS
67boolean value, loop, test, while
Note: See TracBrowser for help on using the repository browser.