Bird
0
0

How can you use an until loop to repeatedly ask the user for input until they type 'exit' in Ruby?

hard📝 Application Q9 of 15
Ruby - Loops and Iteration
How can you use an until loop to repeatedly ask the user for input until they type 'exit' in Ruby?
Ainput = '' until input != 'exit' do puts 'Enter command:' input = gets.chomp end
Binput = '' until input == 'exit' do puts 'Enter command:' input = gets.chomp end
Cinput = '' while input != 'exit' do puts 'Enter command:' input = gets.chomp end
Dinput = '' while input == 'exit' do puts 'Enter command:' input = gets.chomp end
Step-by-Step Solution
Solution:
  1. Step 1: Understand loop condition for until

    Until loop runs while condition is false; so it runs until input equals 'exit'.
  2. Step 2: Check input reading and loop logic

    Input is read inside loop; loop stops when input == 'exit'.
  3. Final Answer:

    input = '' until input == 'exit' do puts 'Enter command:' input = gets.chomp end -> Option B
  4. Quick Check:

    Until loop with user input = A [OK]
Quick Trick: Until runs until input equals exit [OK]
Common Mistakes:
  • Using wrong condition logic
  • Confusing until with while
  • Not updating input inside loop

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes