A simple Q and A quiz that reinforces Ruby learning I wrote a simple quiz which I am hoping to scale-up as I continue to learn about programming.

The code now stores questions and answers in separate arrays. 

Please review this code to improve its efficacy. 

questions = []
answers = []
q0 = "What is the command for a 'for' loop?"
a0 = "for"
q1 = "What is another name for a method?"
a1 = "function"
q2 = "what are the three types of loops that I know of?"
a2 = "while, for, and until"

questions.push(q0, q1, q2)
answers.push(a0, a1, a2)

question_counter = 0
index = 0

while true
  puts questions[index]
  question_counter += 1
  answer_attempt = gets.chomp.downcase
  if answer_attempt == answers[index]
    puts "Good job. Next question.."
  else
    puts "Incorrect. Next question"
  end
  index = index + 1
  if question_counter == 3
    puts "all done"
    break
  end
end
Store related data in a Hash

Also, looping like you've done is very uncommon in Ruby. You'll see Array#each (or Hash#each in this case) much more common than storing an index in a var while iterating through indexes.

@success_msg = 'Good job. Next question..'
@incorrect_msg = 'Incorrect. Next question..'
{
  "What is the command for a 'for' loop?" =&gt; 'for',
  'What is another name for a method?' =&gt; 'function',
  'What are the three types of loops that I know of?' =&gt; 'while, for, and until'
}.each do |q, a|
  puts q
  puts(gets.chomp.downcase == a ? @success_msg : @incorrect_msg)
end
puts 'All done.'


Also, I'd try to make this multiple choice or something if you're really trying to use it, theres no way your response is going to match those answers exactly. Perhaps you could look for certain terms in the response, but parsing English for semantic meaning isn't very easy hehe.