From: Robert Klemme Date: 2005-06-19T06:20:34+09:00 Subject: Re: Newbe questions... Sebastian Biallas wrote: > Chuck Brotman wrote: >> In Ruby Is there a prefered (or otherwise elegant) way to do an >> inner & outer loop with two variables? > > Well, just nest a second loop into the outer loop... > >> >> eg in psedocode: >> >> for i=1 to 3 >> {for j = 4 to 6 >> print i,j, i*j,\nl} >> >> > [..] > >> Also,how would you generate the same output using the each iterator? > > (1..3).each do |i| > (4..6).each do |j| > printf "%d, %d, %d\n", i, j, i*j > end > end > >> >> >> Thanks, >> Chuck > > Sebastian Then there's for ..in: for i in 1..3 begin for j in 4..6 p [i,j,i*j] end end end HTH robert