Bird
0
0

Identify the error in this Kotlin code:

medium📝 Debug Q6 of 15
Kotlin - Loops and Ranges
Identify the error in this Kotlin code:
var n = 0
while n < 5 {
  println(n)
  n++
}
AMissing braces for loop body
BMissing parentheses around condition
CIncorrect increment syntax
DVariable n not initialized
Step-by-Step Solution
Solution:
  1. Step 1: Check while loop syntax

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

    Code has while n < 5 { missing parentheses around n < 5.
  3. Final Answer:

    Missing parentheses around condition -> Option B
  4. Quick Check:

    while condition must be in parentheses = B [OK]
Quick Trick: Always put condition in parentheses for while [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses
  • Misplacing braces
  • Wrong increment operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes