Bird
0
0

You want to check if a number n is between 10 and 20 inclusive in Swift. Which logical expression correctly does this?

hard📝 Application Q8 of 15
Swift - Operators and Expressions
You want to check if a number n is between 10 and 20 inclusive in Swift. Which logical expression correctly does this?
An > 10 && n < 20
Bn > 10 || n < 20
Cn >= 10 || n <= 20
Dn >= 10 && n <= 20
Step-by-Step Solution
Solution:
  1. Step 1: Understand the range condition

    To check if n is between 10 and 20 inclusive, n must be greater or equal to 10 and less or equal to 20.
  2. Step 2: Match with logical operators

    AND (&&) combines both conditions; OR (||) would allow values outside the range.
  3. Final Answer:

    n >= 10 && n <= 20 -> Option D
  4. Quick Check:

    Use AND to check both range limits [OK]
Quick Trick: Use && to combine lower and upper bounds [OK]
Common Mistakes:
  • Using OR instead of AND
  • Using strict > or < instead of >= or <=
  • Mixing conditions incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes