Posted to tcl by aspect at Sat Jan 12 05:40:03 GMT 2013view pretty

proc nestedForeach {args} {
    set body [lindex $args end]
    set args [lreplace $args end end]
    foreach {values key} [lreverse $args] {
        set body [list foreach $key $values $body]
    }
    uplevel 1 $body
}