Bird
0
0

Find the problem in this Kotlin code:

medium📝 Debug Q7 of 15
Kotlin - Loops and Ranges
Find the problem in this Kotlin code:
val items = listOf("one", "two", "three")
for ((i, v) in items.withIndex()) {
  if (i = 1) println(v)
}
AIncorrect destructuring syntax
BUsing assignment (=) instead of comparison (==) in if condition
CwithIndex() cannot be used in if condition
Dprintln cannot be used inside if
Step-by-Step Solution
Solution:
  1. Step 1: Check if condition syntax

    The condition uses assignment (=) instead of equality check (==), causing error.
  2. Step 2: Confirm correct operator

    Use i == 1 to compare index value.
  3. Final Answer:

    Using assignment (=) instead of comparison (==) in if condition -> Option B
  4. Quick Check:

    Use == for comparison in if [OK]
Quick Trick: Use '==' for comparison, not '=' in conditions [OK]
Common Mistakes:
MISTAKES
  • Using = instead of ==
  • Misplacing if condition
  • Wrong destructuring

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes