'''dict for''' ''{keyVar valueVar}'' ''dictionaryValue'' ''body'' This command takes three arguments, the first a two-element list of variable names (for the key and value respectively of each mapping in the dictionary), the second the dictionary value to iterate across, and the third a script to be evaluated for each mapping with the key and value variables set appropriately (in the manner of foreach.) The result of the command is an empty string. If any evaluation of the body generates a TCL_BREAK result, no further pairs from the dictionary will be iterated over and the dict for command will terminate successfully immediately. If any evaluation of the body generates a TCL_CONTINUE result, this shall be treated exactly like a normal TCL_OK result. The order of iteration is the order in which the keys were inserted into the dictionary. ====== # Data for one employee dict set employeeInfo 12345-A forenames "Joe" dict set employeeInfo 12345-A surname "Schmoe" dict set employeeInfo 12345-A street "147 Short Street" dict set employeeInfo 12345-A city "Springfield" dict set employeeInfo 12345-A phone "555-1234" # Data for another employee dict set employeeInfo 98372-J forenames "Anne" dict set employeeInfo 98372-J surname "Other" dict set employeeInfo 98372-J street "32995 Oakdale Way" dict set employeeInfo 98372-J city "Springfield" dict set employeeInfo 98372-J phone "555-8765" # The above data probably ought to come from a database... # Print out some employee info set i 0 puts "There are [dict size $employeeInfo] employees" dict for {id info} $employeeInfo { puts "Employee #[incr i]: $id" dict with info { puts " Name: $forenames $surname" puts " Address: $street, $city" puts " Telephone: $phone" } } # Another way to iterate and pick out names... foreach id [dict keys $employeeInfo] { puts "Hello, [dict get $employeeInfo $id forenames]!" } ====== <>Command | Data Structure