summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-05-05 22:08:08 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-05-05 22:08:08 (GMT)
commit4149000e58b323d2eab144b32acfa9f62e8576f1 (patch)
tree884440c3281c800096ae9cfc9671820ee7b95210 /doc
parentff3d3775756945e7174da795eb668a5f88016267 (diff)
downloadtcl-4149000e58b323d2eab144b32acfa9f62e8576f1.zip
tcl-4149000e58b323d2eab144b32acfa9f62e8576f1.tar.gz
tcl-4149000e58b323d2eab144b32acfa9f62e8576f1.tar.bz2
More examples.
Diffstat (limited to 'doc')
-rw-r--r--doc/for.n29
-rw-r--r--doc/while.n11
2 files changed, 35 insertions, 5 deletions
diff --git a/doc/for.n b/doc/for.n
index 5cf267c..2b98453 100644
--- a/doc/for.n
+++ b/doc/for.n
@@ -5,7 +5,7 @@
'\" 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 2000/09/07 14:27:48 poenitz Exp $
+'\" RCS: @(#) $Id: for.n,v 1.4 2004/05/05 22:08:10 dkf Exp $
'\"
.so man.macros
.TH for n "" Tcl "Tcl Built-In Commands"
@@ -48,11 +48,32 @@ 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:
+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"
+ puts "x is $x"
+}
+.CE
+
+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 \fIx\fR exists
+before the \fBfor\fR 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 \fBfor\fR command is
+executed.
+.CS
+for {set x 0} $x<10 {incr x} {
+ puts "x is $x"
+}
+.CE
+
+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
diff --git a/doc/while.n b/doc/while.n
index ba5a584..e1c2ec3 100644
--- a/doc/while.n
+++ b/doc/while.n
@@ -5,7 +5,7 @@
'\" 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 2000/09/07 14:27:52 poenitz Exp $
+'\" RCS: @(#) $Id: while.n,v 1.4 2004/05/05 22:08:10 dkf Exp $
'\"
.so man.macros
.TH while n "" Tcl "Tcl Built-In Commands"
@@ -50,6 +50,15 @@ while {$x<10} {
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
+while {[gets $chan line] >= 0} {
+ puts "[incr lineCount]: $line"
+}
+.CE
.SH "SEE ALSO"
break(n), continue(n), for(n), foreach(n)