Bird
0
0

Identify the mistake in this Kotlin code snippet:

medium📝 Debug Q7 of 15
Kotlin - Operators and Expressions
Identify the mistake in this Kotlin code snippet:
val range = 1..10
if (15 in range) println("Inside") else println("Outside")
ANo mistake, code works fine
B15 is outside the range, but code is correct
CRange should be reversed for 15
DUse 'in' operator only with lists
Step-by-Step Solution
Solution:
  1. Step 1: Check range and value

    Range is 1 to 10, 15 is outside this range.
  2. Step 2: Check code correctness

    Code correctly uses 'in' operator; it will print "Outside" because 15 is not in range.
  3. Final Answer:

    15 is outside the range, but code is correct -> Option B
  4. Quick Check:

    Code logic is correct even if value is outside range [OK]
Quick Trick: Value outside range prints else branch [OK]
Common Mistakes:
MISTAKES
  • Thinking code has syntax error
  • Assuming 'in' only works for inside values
  • Confusing range boundaries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes