Bird
0
0

Find the error in this Kotlin code:

medium📝 Debug Q7 of 15
Kotlin - Control Flow as Expressions
Find the error in this Kotlin code:
val max = if (a > b) a else
println(max)
Aif cannot be used without braces
BIncorrect println syntax
CVariable max not declared
DMissing value after else
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the if expression structure

    If expression must have both then and else values to return.
  2. Step 2: Identify missing else value

    Code has else but no value after it, causing syntax error.
  3. Final Answer:

    Missing value after else -> Option D
  4. Quick Check:

    If expression else must have a value [OK]
Quick Trick: Else branch must always return a value in if expression [OK]
Common Mistakes:
MISTAKES
  • Leaving else empty
  • Assuming println error
  • Missing variable declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes