summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorhobbs <hobbs>2003-07-07 20:36:32 (GMT)
committerhobbs <hobbs>2003-07-07 20:36:32 (GMT)
commit2261616ddbbf824bbb6b7edafe1269baf0ce0f94 (patch)
tree089d83212e9aa0a0c3cf65143fbe1db511aa2b9a /doc
parentb2dec639457530aa167e1d9929cce2ed56f415fb (diff)
downloadtcl-2261616ddbbf824bbb6b7edafe1269baf0ce0f94.zip
tcl-2261616ddbbf824bbb6b7edafe1269baf0ce0f94.tar.gz
tcl-2261616ddbbf824bbb6b7edafe1269baf0ce0f94.tar.bz2
doc/array.n: add examples from Welton
Diffstat (limited to 'doc')
-rw-r--r--doc/array.n30
1 files changed, 27 insertions, 3 deletions
diff --git a/doc/array.n b/doc/array.n
index b04c89f..4759dd7 100644
--- a/doc/array.n
+++ b/doc/array.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: array.n,v 1.8 2000/09/07 14:27:45 poenitz Exp $
+'\" RCS: @(#) $Id: array.n,v 1.9 2003/07/07 20:36:32 hobbs Exp $
'\"
.so man.macros
.TH array n 8.3 Tcl "Tcl Built-In Commands"
@@ -114,7 +114,9 @@ command should be invoked.
The return value is a
search identifier that must be used in \fBarray nextelement\fR
and \fBarray donesearch\fR commands; it allows multiple
-searches to be underway simultaneously for the same array.
+searches to be underway simultaneously for the same array. Unless
+dealing with a very large array, it is probably easier to use the
+\fBarray get\fR command to loop through an array, as in the examples below.
.VS 8.4
.TP
\fBarray statistics \fIarrayName\fR
@@ -134,8 +136,30 @@ an array variable, then the command unsets the entire array.
The command always returns an empty string.
.VE 8.3
+.SH EXAMPLES
+
+.CS
+array set colorcount {red 1 green 5 blue 4 white 9}
+
+foreach {color count} [array get colorcount] {
+ puts "Color: $color Count: $count"
+}
+ => Color: blue Count: 4
+ Color: white Count: 9
+ Color: green Count: 5
+ Color: red Count: 1
+
+foreach color [array names colorcount] {
+ puts "Color: $color Count: $colorcount($color)"
+}
+ => Color: blue Count: 4
+ Color: white Count: 9
+ Color: green Count: 5
+ Color: red Count: 1
+.CE
+
.SH "SEE ALSO"
-list(n), string(n), variable(n), trace(n)
+list(n), string(n), variable(n), trace(n), foreach(n)
.SH KEYWORDS
array, element names, search