Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Foreach loop
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Tcl === [[Tcl]] uses foreach to iterate over lists. It is possible to specify more than one iterator variable, in which case they are assigned sequential values from the list. {| class="wikitable" ! code !! prints |- | <syntaxhighlight lang=Tcl> foreach {i j} {1 2 3 4 5 6} { puts "$i $j" } </syntaxhighlight> | 1 2 3 4 5 6 |} It is also possible to iterate over more than one list simultaneously. In the following <code>i</code> assumes sequential values of the first list, <code>j</code> sequential values of the second list: {| class="wikitable" ! code !! prints |- | <syntaxhighlight lang=Tcl> foreach i {1 2 3} j {a b c} { puts "$i $j" } </syntaxhighlight> | 1 a 2 b 3 c |}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)