Bird
0
0

How would you write a condition to check if $value is less than 20 or equal to 30 in PowerShell?

hard📝 Application Q9 of 15
PowerShell - Operators
How would you write a condition to check if $value is less than 20 or equal to 30 in PowerShell?
Aif ($value -lt 20 -or $value -eq 30) { 'True' }
Bif ($value -lt 20 -and $value -eq 30) { 'True' }
Cif ($value -gt 20 -or $value -ne 30) { 'True' }
Dif ($value -gt 20 -and $value -eq 30) { 'True' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition logic

    We want to check if $value is less than 20 OR equal to 30.
  2. Step 2: Use correct operators and logical connector

    -lt for less than, -eq for equal, and -or to combine conditions.
  3. Final Answer:

    if ($value -lt 20 -or $value -eq 30) { 'True' } -> Option A
  4. Quick Check:

    Use -or for either condition true [OK]
Quick Trick: Use -or to check if either condition is true [OK]
Common Mistakes:
  • Using -and instead of -or
  • Wrong comparison operators
  • Confusing greater than with less than

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes