Bird
0
0

Identify the error in this Kotlin code snippet:

medium📝 Debug Q14 of 15
Kotlin - Loops and Ranges
Identify the error in this Kotlin code snippet:
var i = 1
do {
    println(i)
    i++
} while i <= 3
AMissing braces around the do block
BIncorrect use of do keyword
CVariable i should be declared inside the loop
DMissing parentheses around the while condition
Step-by-Step Solution
Solution:
  1. Step 1: Check do-while syntax

    The while condition must be inside parentheses after the while keyword.
  2. Step 2: Identify the error in the code

    The code has while i <= 3 without parentheses. It should be while (i <= 3).
  3. Final Answer:

    Missing parentheses around the while condition -> Option D
  4. Quick Check:

    Parentheses required for while condition = Missing parentheses around the while condition [OK]
Quick Trick: Always put condition in parentheses after while [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses in while condition
  • Placing variable declaration inside loop unnecessarily
  • Confusing braces and parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes