Bird
0
0

What will be the output of this Kotlin code?

medium📝 Predict Output Q5 of 15
Kotlin - Loops and Ranges
What will be the output of this Kotlin code?
for (i in 1 until 4) { print(i) }
A124
B1234
C123
DError
Step-by-Step Solution
Solution:
  1. Step 1: Understand the until keyword

    1 until 4 means from 1 up to but not including 4.
  2. Step 2: Loop prints 1, 2, 3

    The loop prints numbers 1, 2, and 3 without spaces.
  3. Final Answer:

    123 -> Option C
  4. Quick Check:

    until excludes end number [OK]
Quick Trick: until excludes the end number [OK]
Common Mistakes:
MISTAKES
  • Confusing until with ..
  • Expecting 4 to be printed
  • Thinking until includes end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes