From: "pimea.mark" Date: 2007-12-13T01:20:09+09:00 Subject: Re: While statements in ruby On Dec 11, 11:41 am, Chris Shea wrote: > On Dec 11, 10:25 am, 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] > > > } > > > 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] > > > } > > > -- > > Posted viahttp://www.ruby-forum.com/. > > If you are really just working with two arrays that map one-to-one and > onto each other, why not use one array? An array of hashes perhaps. > Like: > > q_and_as = [ {:question => 'Is it blue?', :answer => 'Yes'}, > {:question => 'Is it round?', :answer => 'No'} ] > > Then use Array's each method: > > q_and_as.each do |query| > puts "#{query[:question]}" > puts "#{query[:answer]}" > end > > HTH, > Chris Yeah I wanted to do this as well but didn't know how in ruby :) Could you tell me how you'd add to an array like this using variables inside a loop? Like if you didnt manually enter the values.