Bird
0
0

Find the mistake in this code snippet:

medium📝 Debug Q7 of 15
PowerShell - Operators
Find the mistake in this code snippet:
$num = 5
if ($num -lt 10)
'Less'
else
'More'
AWrong comparison operator used
BVariable $num is not declared
CMissing curly braces for if and else blocks
DQuotes missing around output strings
Step-by-Step Solution
Solution:
  1. Step 1: Review if-else syntax in PowerShell

    PowerShell requires curly braces {} to group statements in if and else blocks.
  2. Step 2: Identify missing braces

    The code lacks curly braces around the 'Less' and 'More' outputs, which can cause errors or unexpected behavior.
  3. Final Answer:

    Missing curly braces for if and else blocks -> Option C
  4. Quick Check:

    Use braces to group code in if-else [OK]
Quick Trick: Always use braces {} for if and else blocks [OK]
Common Mistakes:
  • Omitting braces
  • Using wrong operators
  • Not declaring variables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes