Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Loops and Iteration
Identify the error in this Ruby code snippet:
5.times do i
  puts i
end
Aputs cannot be used inside times block
Btimes method cannot be used with do...end
CMissing block parameter pipes | | around i
DInteger 5 cannot call times method
Step-by-Step Solution
Solution:
  1. Step 1: Check block parameter syntax

    In Ruby, block parameters must be enclosed in pipes: do |i| ... end.
  2. Step 2: Identify the missing pipes causing syntax error

    The code uses do i without pipes, which is invalid syntax.
  3. Final Answer:

    Missing block parameter pipes | | around i -> Option C
  4. Quick Check:

    Block params need |i|, not just i [OK]
Quick Trick: Always use |param| in block headers [OK]
Common Mistakes:
  • Omitting pipes around block parameters
  • Thinking do/end can't be used with times
  • Misunderstanding times method usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes