Bird
0
0

Which Kotlin code snippet correctly prints numbers 0 to 3 using repeat?

easy📝 Syntax Q3 of 15
Kotlin - Loops and Ranges
Which Kotlin code snippet correctly prints numbers 0 to 3 using repeat?
Arepeat(3) { println(it) }
Brepeat { println(it) }(4)
Crepeat(4) println(it)
Drepeat(4) { println(it) }
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range of repeat

    repeat(4) runs the block 4 times with it from 0 to 3.
  2. Step 2: Check syntax correctness

    repeat(4) { println(it) } uses correct syntax and prints 0,1,2,3. Others have wrong counts or syntax errors.
  3. Final Answer:

    repeat(4) { println(it) } -> Option D
  4. Quick Check:

    repeat(4) prints 0 to 3 [OK]
Quick Trick: repeat(n) runs block with it from 0 to n-1 [OK]
Common Mistakes:
MISTAKES
  • Using wrong repeat count
  • Missing braces for lambda
  • Trying to use it outside lambda

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes