Bird
0
0

Which of the following is the correct syntax to use each on an array numbers to print each number?

easy📝 Syntax Q12 of 15
Ruby - Loops and Iteration
Which of the following is the correct syntax to use each on an array numbers to print each number?
Aeach numbers { |num| puts num }
Bnumbers.each do num puts num end
Cnumbers.each { |num| puts num }
Dnumbers.each |num| puts num
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct block syntax with each

    The correct syntax uses each followed by a block with { |variable| ... } or do |variable| ... end.
  2. Step 2: Check each option

    numbers.each { |num| puts num } uses numbers.each { |num| puts num } which is correct. Others have syntax errors or wrong order.
  3. Final Answer:

    numbers.each { |num| puts num } -> Option C
  4. Quick Check:

    Correct block syntax = numbers.each { |num| puts num } [OK]
Quick Trick: Use each { |item| ... } or each do |item| ... end [OK]
Common Mistakes:
MISTAKES
  • Writing each numbers instead of numbers.each
  • Missing block delimiters like braces or do-end
  • Not using pipes | | around block variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes