Bird
0
0

What is the output of this Kotlin code?

medium📝 Predict Output Q4 of 15
Kotlin - Loops and Ranges
What is the output of this Kotlin code?
var i = 1
while (i <= 3) {
  print(i)
  i++
}
A321
B12
C1 2 3
D123
Step-by-Step Solution
Solution:
  1. Step 1: Trace the while loop iterations

    Variable i starts at 1 and increments by 1 each loop until i > 3.
  2. Step 2: Determine printed output

    Prints 1, then 2, then 3 without spaces or newlines.
  3. Final Answer:

    123 -> Option D
  4. Quick Check:

    While loop prints 1 to 3 consecutively = A [OK]
Quick Trick: print() without newline prints values together [OK]
Common Mistakes:
MISTAKES
  • Expecting spaces between numbers
  • Thinking loop stops early
  • Confusing print and println

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes