Bird
0
0

Find the problem in this Kotlin code snippet:

medium📝 Debug Q7 of 15
Kotlin - Control Flow as Expressions
Find the problem in this Kotlin code snippet:
val score = 85
when {
  score >= 90 -> println("A")
  score >= 80 -> println("B")
  score >= 70 -> println("C")
  else println("F")
}
AMissing arrow (->) after else
BConditions are in wrong order
Cscore variable is immutable
DNo problem, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of else branch

    Else branch must have -> before action.
  2. Step 2: Identify missing arrow

    Else branch is missing -> before println("F").
  3. Final Answer:

    Missing arrow (->) after else -> Option A
  4. Quick Check:

    else branch requires -> before action [OK]
Quick Trick: Don't forget -> after else in when without argument [OK]
Common Mistakes:
MISTAKES
  • Omitting -> after else
  • Thinking else can omit arrow
  • Reordering conditions unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes