Bird
0
0

Which of the following is the correct syntax to create an infinite loop using the loop method in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Loops and Iteration
Which of the following is the correct syntax to create an infinite loop using the loop method in Ruby?
Aloop: do puts "Hi" end
Bloop { puts "Hi" do end }
Cloop puts "Hi" do end
Dloop { puts "Hi" }
Step-by-Step Solution
Solution:
  1. Step 1: Review Ruby loop syntax

    The loop method can take a block with curly braces or do...end.
  2. Step 2: Identify correct syntax

    loop { puts "Hi" } uses loop { puts "Hi" }, which is valid Ruby syntax for an infinite loop.
  3. Final Answer:

    loop { puts "Hi" } -> Option D
  4. Quick Check:

    loop with block braces is valid syntax [OK]
Quick Trick: Use loop with { } or do...end for blocks [OK]
Common Mistakes:
  • Placing do after loop without block
  • Using colon incorrectly
  • Missing block braces or do...end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes