Bird
0
0

What is wrong with this Kotlin code?

medium📝 Debug Q7 of 15
Kotlin - Loops and Ranges
What is wrong with this Kotlin code?
var i = 1
do {
  println(i)
} while i < 5
AMissing parentheses around condition in do-while
BMissing braces for do-while body
CVariable i not incremented
Ddo-while loops cannot use println
Step-by-Step Solution
Solution:
  1. Step 1: Check do-while syntax

    Kotlin requires parentheses around the condition in a do-while loop.
  2. Step 2: Identify missing parentheses

    Condition i < 5 is not inside parentheses after while.
  3. Final Answer:

    Missing parentheses around condition in do-while -> Option A
  4. Quick Check:

    do-while condition needs parentheses = C [OK]
Quick Trick: Put condition in parentheses after while in do-while [OK]
Common Mistakes:
MISTAKES
  • Forgetting parentheses
  • Not incrementing loop variable
  • Thinking println causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes