Bird
0
0

Which of the following is the correct syntax to count down from 10 to 7 using downto in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Loops and Iteration
Which of the following is the correct syntax to count down from 10 to 7 using downto in Ruby?
A10.downto(7) { |i| puts i }
B10.upto(7) { |i| puts i }
C7.downto(10) { |i| puts i }
D7.upto(10) { |i| puts i }
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct method for counting down

    To count down from 10 to 7, use downto starting at 10 and ending at 7.
  2. Step 2: Check syntax correctness

    10.downto(7) { |i| puts i } correctly counts down and prints each number.
  3. Final Answer:

    10.downto(7) { |i| puts i } -> Option A
  4. Quick Check:

    Count down syntax = C [OK]
Quick Trick: downto starts at bigger number, ends at smaller [OK]
Common Mistakes:
  • Using upto instead of downto for counting down
  • Reversing start and end numbers
  • Missing the block syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes