From: "Carlo E. Prelz" Date: 2012-12-08T16:29:42+09:00 Subject: Re: if n belongs to set a and m belongs to set b repeat some steps, How? Subject: if n belongs to set a and m belongs to set b repeat some steps, How? Date: Sat 08 Dec 12 02:05:33PM +0900 Quoting zubair a. (lists@ruby-forum.com): > We can do so in java and similar languages like: > > for (int i=0, int j=3; i<=2 && j<=5;i++,j++){ > do some repetive task until the condition becomes false... > } > > how to keep these two conditions based on two different sets(suppose two > arrays whose indexes can be used as i and j) in condition block?? The simplest way is just to unroll the C construct: i=0 j=3 while(i<=2 && j<=5) .. .. .. i+=1 j+=1 end It is less neat, I am afraid, but it works the same way. I often use for loops like that in C, but when I write in Ruby I know I must express the algorithm in a different way. Ruby loops manage only one variable. How I do it depends on the case. In your example, for example, the loop runs 3 times (unless you modify the loop variables within the loop itself), and j is always equal to i+3. Thus I could do 3.times do |i| .. .. end and inside the loop, when in need of the 'j' value, I'd instead use 'i+3'. Carlo -- * Se la Strada e la sua Virtu' non fossero state messe da parte, * K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)