Bird
0
0

You want to check if a number $n is between 10 and 20 inclusive in PowerShell. Which expression correctly uses comparison and logical operators?

hard📝 Application Q15 of 15
PowerShell - Operators
You want to check if a number $n is between 10 and 20 inclusive in PowerShell. Which expression correctly uses comparison and logical operators?
Aif ($n -ge 10 -and $n -le 20) { 'In range' }
Bif ($n -gt 10 -or $n -lt 20) { 'In range' }
Cif ($n -ge 10 -or $n -le 20) { 'In range' }
Dif ($n -gt 10 -and $n -lt 20) { 'In range' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand inclusive range check

    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: Match operators to conditions

    -ge means greater or equal, -le means less or equal, and both conditions must be true, so use -and.
  3. Final Answer:

    if ($n -ge 10 -and $n -le 20) { 'In range' } -> Option A
  4. Quick Check:

    Inclusive range uses -ge and -le with -and [OK]
Quick Trick: Use -ge and -le with -and for inclusive range checks [OK]
Common Mistakes:
  • Using -or instead of -and
  • Using strict > and < instead of >= and <=
  • Mixing up logical operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes