summaryrefslogtreecommitdiffstats
path: root/Doc/lib/libcodecs.tex
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2011-05-28 11:58:36 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2011-05-28 11:58:36 (GMT)
commit11a859d70dffc8da51d346dabd1fe6a635825ae5 (patch)
tree253910e2a0811d6cb4848049a465fd0289918e48 /Doc/lib/libcodecs.tex
parente81c485e5778b1dd628f4bf0f5aecd16d02f91df (diff)
downloadcpython-2.5.6.zip
cpython-2.5.6.tar.gz
cpython-2.5.6.tar.bz2
r88840: Prepare for 2.5.6.v2.5.6
Diffstat (limited to 'Doc/lib/libcodecs.tex')
0 files changed, 0 insertions, 0 deletions
480599 Tcl is a high-level, general-purpose, interpreted, dynamic programming language. It was designed with the goal of being very simple but powerful.
summaryrefslogtreecommitdiffstats
path: root/doc/while.n
blob: da498531fa51f2197fe564de9e1ae4b799f2c277 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'\"
'\" 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.
'\" 
.TH while n "" Tcl "Tcl Built-In Commands"
.so man.macros
.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 body\fR
.BE

.SH DESCRIPTION
.PP
The \fBwhile\fR command evaluates \fItest\fR as an expression
(in the same way that \fBexpr\fR evaluates its argument).
The value of the expression must a proper boolean
value; if it is a true value
then \fIbody\fR is executed by passing it to the Tcl interpreter.
Once \fIbody\fR has been executed then \fItest\fR is evaluated
again, and the process repeats until eventually \fItest\fR
evaluates to a false boolean value.  \fBContinue\fR
commands may be executed inside \fIbody\fR to terminate the current
iteration of the loop, and \fBbreak\fR
commands may be executed inside \fIbody\fR to cause immediate
termination of the \fBwhile\fR command.  The \fBwhile\fR command
always returns an empty string.
.PP
Note: \fItest\fR should almost always be enclosed in braces.  If not,
variable substitutions will be made before the \fBwhile\fR
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 \fItest\fR 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<10\fR:
.CS
set x 0
\fBwhile\fR {$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
\fBwhile\fR {[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