Bird
0
0

Identify the error in this PowerShell snippet:

medium📝 Debug Q6 of 15
PowerShell - Control Flow
Identify the error in this PowerShell snippet:
if ($y -eq 10) Write-Output 'Match'
AMissing braces {} around the if statement block
BIncorrect comparison operator used
CVariable $y is not declared
DWrite-Output cannot be used inside if statements
Step-by-Step Solution
Solution:
  1. Step 1: Review if statement syntax

    PowerShell allows single statements without braces, but best practice is to use braces for clarity and multi-line blocks.
  2. Step 2: Analyze the snippet

    The snippet lacks braces, which is syntactically valid but may be considered poor style or error-prone.
  3. Step 3: Validate other options

    Comparison operator and variable usage are correct; Write-Output is valid inside if.
  4. Final Answer:

    Missing braces {} around the if statement block -> Option A
  5. Quick Check:

    Use braces for clarity in if blocks [OK]
Quick Trick: Always use braces {} for if blocks [OK]
Common Mistakes:
  • Omitting braces in multi-line if blocks
  • Confusing comparison operators
  • Assuming Write-Output is invalid inside if

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes