Bird
0
0

Which of these is a correct way to use times to print "Hello" 3 times in Ruby?

easy📝 Conceptual Q2 of 15
Ruby - Loops and Iteration
Which of these is a correct way to use times to print "Hello" 3 times in Ruby?
A3.times { puts "Hello" }
Btimes(3) { puts "Hello" }
C"Hello".times(3)
D3.times.puts("Hello")
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct times syntax

    The times method is called on an integer with a block: 3.times { ... }.
  2. Step 2: Check each option's syntax

    Only 3.times { puts "Hello" } uses the correct syntax. Others misuse method calls or receiver types.
  3. Final Answer:

    3.times { puts "Hello" } -> Option A
  4. Quick Check:

    Correct syntax = 3.times { block } [OK]
Quick Trick: Call times on integer with block: n.times { ... } [OK]
Common Mistakes:
  • Trying to call times on a string
  • Passing argument inside times method
  • Using dot notation incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes