for animal, color in zip(['dog', 'cat', 'bird'], ['brown', 'black', 'red']):
print 'See the %s %s?' % (color, animal) for animal, color in zip(['dog', 'cat', 'bird'], ['brown', 'black', 'red']):
print 'See the %s %s?' % (color, animal)Still, I wish more languages directly imitated the TCL foreach loop. I've found that when I code, I wish I could just do some simple task 3-4 times. I am always tempted to create a little function, and to call that function repeatedly. But that seems like overkill. With TCL, I just write a simple loop statement instead of the function. I've found that my code is more compact, and the number of functions that I declare is reduced.
['dog', 'cat', 'bird'].zip(['brown', 'black', 'red']).each {|animal, color| puts "See the #{color} #{animal}?"}