Bird
0
0

Which of the following Swift expressions correctly checks if a variable num lies between 5 and 15 inclusive?

hard📝 Application Q8 of 15
Swift - Operators and Expressions
Which of the following Swift expressions correctly checks if a variable num lies between 5 and 15 inclusive?
Anum >= 5 || num <= 15
Bnum > 5 && num < 15
C5 <= num && num <= 15
Dnum > 5 || num < 15
Step-by-Step Solution
Solution:
  1. Step 1: Understand inclusive range

    Inclusive means including 5 and 15, so use <= and >= operators.
  2. Step 2: Combine conditions correctly

    Use logical AND (&&) to ensure num is both >=5 and <=15.
  3. Final Answer:

    5 <= num && num <= 15 -> Option C
  4. Quick Check:

    Inclusive range uses <= and >= with && [OK]
Quick Trick: Use && with <= and >= for inclusive range [OK]
Common Mistakes:
  • Using > and < instead of >= and <=
  • Using || instead of && for range checks
  • Confusing inclusive with exclusive ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Swift Quizzes