summaryrefslogtreecommitdiffstats
path: root/doc/foreach.n
diff options
context:
space:
mode:
Diffstat (limited to 'doc/foreach.n')
-rw-r--r--doc/foreach.n15
1 files changed, 9 insertions, 6 deletions
diff --git a/doc/foreach.n b/doc/foreach.n
index 5d3a631..89a11f6 100644
--- a/doc/foreach.n
+++ b/doc/foreach.n
@@ -5,10 +5,8 @@
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
-'\" RCS: @(#) $Id: foreach.n,v 1.8 2006/11/15 09:23:01 dkf Exp $
-'\"
-.so man.macros
.TH foreach n "" Tcl "Tcl Built-In Commands"
+.so man.macros
.BS
'\" Note: do not modify the .SH NAME line immediately below!
.SH NAME
@@ -51,20 +49,23 @@ The \fBbreak\fR and \fBcontinue\fR statements may be
invoked inside \fIbody\fR, with the same effect as in the \fBfor\fR
command. \fBForeach\fR returns an empty string.
.SH EXAMPLES
+.PP
This loop prints every value in a list together with the square and
cube of the value:
+.PP
.CS
'\" Maintainers: notice the tab hacking below!
.ta 3i
set values {1 3 5 7 2 4 6 8} ;# Odd numbers first, for fun!
-puts "Value\\tSquare\\tCube" ;# Neat-looking header
+puts "Value\etSquare\etCube" ;# Neat-looking header
\fBforeach\fR x $values { ;# Now loop and print...
- puts " $x\\t [expr {$x**2}]\\t [expr {$x**3}]"
+ puts " $x\et [expr {$x**2}]\et [expr {$x**3}]"
}
.CE
.PP
The following loop uses i and j as loop variables to iterate over
pairs of elements of a single list.
+.PP
.CS
set x {}
\fBforeach\fR {i j} {a b c d e f} {
@@ -75,6 +76,7 @@ set x {}
.CE
.PP
The next loop uses i and j to iterate over two lists in parallel.
+.PP
.CS
set x {}
\fBforeach\fR i {a b c} j {d e f g} {
@@ -85,6 +87,7 @@ set x {}
.CE
.PP
The two forms are combined in the following example.
+.PP
.CS
set x {}
\fBforeach\fR i {a b c} {j k} {d e f g} {
@@ -98,4 +101,4 @@ set x {}
for(n), while(n), break(n), continue(n)
.SH KEYWORDS
-foreach, iteration, list, looping
+foreach, iteration, list, loop