array startsearch
Starts a search through the elements of an array, and gives its id.
array startsearch ARRAYNAME
Description
Starts a search: the old way to go through an array one element at a time, with array nextelement, array anymore, and array donesearch. The id has the form s-N-ARRAYNAME, with N the count of searches of the array. An array can have more than one search at a time.
A new element of the array ends each search of it: a later use of the id is an error. Use array for in Tcl 9.1, or foreach over array names, in place of a search.
Arguments
| Argument | Type | Default | Description |
|---|---|---|---|
| ARRAYNAME | variable name | required | The array to go through. |
Returns
The id of the search, such as s-1-a.
Examples
% array set c {p 1 q 2}; set id [array startsearch c]
s-1-c
% array startsearch c
s-2-c
# A new element ends the search.
% set id2 [array startsearch c]; set c(new) 3; catch {array nextelement c $id2}
1
Errors
% array startsearch nope
"nope" isn't an array
-errorcode TCL LOOKUP ARRAY nope
% array startsearch
wrong # args: should be "array startsearch arrayName"
-errorcode TCL WRONGARGS
Facts
- Capability
- None.
- Tcl release
- Tcl 9.1 and 8.6.
- Since
- ztcl 1.0.0-beta.1