Tcl Source Code

Artifact [b4d8a58809]
Login

Artifact b4d8a58809cf9430c1669cf6dd147e241707a056:

Attachment "array.diff" to ticket [763312ffff] added by davidw 2003-06-30 22:45:13.
Index: array.n
===================================================================
RCS file: /cvsroot/tcl/tcl/doc/array.n,v
retrieving revision 1.8
diff -u -r1.8 array.n
--- array.n	7 Sep 2000 14:27:45 -0000	1.8
+++ array.n	30 Jun 2003 15:41:41 -0000
@@ -114,7 +114,9 @@
 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 @@
 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