From: Robert Klemme Date: 2007-12-12T07:05:16+09:00 Subject: Re: While statements in ruby On 11.12.2007 18:25, Mark Mr wrote: > Hi guys, I have a probably simple question. I dont know how to do > iteration loops in ruby that reference more than one item of an array or > more than one array. Here's an example of what I would do in php. Can > anyone convert this to ruby? Thanks :) > > while ($i=0; $i < $response_table.length; $i += 2) { > > $response_table[$i] > $response_table[$i + 1] > > } I am amazed nobody mentioned each_slice: with "enumerator" you can do: irb(main):006:0> (1..6).each_slice(2) {|a,b| print a,",",b,"\n"} 1,2 3,4 5,6 => nil > or something like this would work too if i made an array for questions > and a separate one for answers > > while ($i=0; $i < array_count; $i++) { > > $question_table[$i] > $answer_table[$i] > > } questions.size.times do |i| puts questions[i], answers[i] end Kind regards robert