Multiple foreach loop variables

   

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

Table of Contents
Chapter 49.  Tcl 7.5/Tk 4.1


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 } 

       
    Top
     



    Practical Programming in Tcl and Tk
    Practical Programming in Tcl and Tk (4th Edition)
    ISBN: 0130385603
    EAN: 2147483647
    Year: 1999
    Pages: 478

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net