Recall & Review
beginner
What is a for loop in PowerShell?
A for loop is a control structure that repeats a block of code a specific number of times. It uses a counter to track iterations.
Click to reveal answer
beginner
What are the three parts of a PowerShell for loop header?
1. Initialization (sets the counter)<br>2. Condition (checks if the loop should continue)<br>3. Increment/Decrement (updates the counter each time)
Click to reveal answer
beginner
How do you write a for loop in PowerShell that counts from 1 to 5?
for ($i = 1; $i -le 5; $i++) {<br> Write-Output $i<br>}
Click to reveal answer
beginner
What happens if the condition in a for loop is never true?
The loop body does not run at all because the condition is checked before each iteration.
Click to reveal answer
intermediate
How can you exit a for loop early in PowerShell?
Use the
break statement inside the loop to stop it immediately.Click to reveal answer
Which part of the for loop controls how many times the loop runs?
✗ Incorrect
The condition is checked before each loop iteration to decide if the loop should continue.
What does this for loop do? for ($i=0; $i -lt 3; $i++) { Write-Output $i }
✗ Incorrect
The loop runs while $i is less than 3, so it prints 0, 1, and 2.
What keyword stops a for loop immediately in PowerShell?
✗ Incorrect
break exits the loop immediately.If the initialization is missing in a for loop, what happens?
✗ Incorrect
The loop behavior depends on the condition and increment; initialization is optional but usually needed.
Which symbol is used for incrementing the counter by 1 in PowerShell for loops?
✗ Incorrect
$i++ increases the counter by 1 each time.Explain how a for loop works in PowerShell and write a simple example that prints numbers from 1 to 3.
Think about setting a counter, checking it, and increasing it each time.
You got /5 concepts.
Describe how you can stop a for loop before it finishes all iterations in PowerShell.
What keyword lets you jump out of the loop?
You got /3 concepts.