Bird
0
0

How can you modify this for loop to skip printing the number 3?

hard📝 Application Q9 of 15
PowerShell - Control Flow

How can you modify this for loop to skip printing the number 3?

for ($i=1; $i -le 5; $i++) { Write-Output $i }
AChange the loop condition to stop at 2
BUse a <code>while</code> loop instead
CRemove the increment operator
DAdd an <code>if</code> statement to continue when $i equals 3
Step-by-Step Solution
Solution:
  1. Step 1: Identify how to skip a value in loop

    Use an if condition to skip printing when $i is 3.
  2. Step 2: Understand other options

    Stopping at 2 misses numbers after 3; removing increment causes infinite loop; while loop is unrelated.
  3. Final Answer:

    Add an if statement to continue when $i equals 3 -> Option D
  4. Quick Check:

    Use condition inside loop to skip values [OK]
Quick Trick: Use if to skip unwanted values inside loop [OK]
Common Mistakes:
  • Stopping loop early instead of skipping
  • Removing increment causing infinite loop
  • Changing loop type unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes