Bird
0
0

You want to check if a number n is between 10 and 20 inclusive in Swift. Which condition correctly uses logical operators?

hard📝 Application Q15 of 15
Swift - Operators and Expressions
You want to check if a number n is between 10 and 20 inclusive in Swift. Which condition correctly uses logical operators?
An >= 10 && n <= 20
Bn > 10 && n < 20
Cn >= 10 || n <= 20
D!(n < 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 than or equal to 10 AND less than or equal to 20.
  2. Step 2: Evaluate each option

    n >= 10 || n <= 20 uses OR which is incorrect because it allows values outside the range. n > 10 && n < 20 excludes 10 and 20 by using > and <. !(n < 10 && n > 20) negates an impossible condition and is incorrect.
  3. Final Answer:

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

    Use AND for range checks [OK]
Quick Trick: Use && to combine lower and upper bounds [OK]
Common Mistakes:
  • Using OR instead of AND for range
  • Excluding boundary values by using > or <
  • Using negation incorrectly for range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes