O'Reilly logo

Practical Programming in Tcl & Tk, Third Edition by Brent B. Welch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Multiple foreach loop variables

This is one of my favorite features. The foreach command supports multiple loop variables and multiple value lists. This means you can assign values to multiple variables during each loop iteration. The values can come from the same list, or from lists that are processed in parallel. This is described on page 75. For example, you can iterate through the contents of an array with:

foreach {name value}[array get arrName] {
    # arrName($name) is $value
}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required