Recall & Review
beginner
What is a While loop in PowerShell?
A While loop repeats a block of code as long as a specified condition is true. It checks the condition before running the code each time.
Click to reveal answer
beginner
How does a Do-While loop differ from a While loop?
A Do-While loop runs the code block first, then checks the condition. This means it always runs at least once, even if the condition is false at the start.
Click to reveal answer
beginner
Write a simple PowerShell While loop that counts from 1 to 3.
$i = 1
while ($i -le 3) {
Write-Output $i
$i += 1
}
Click to reveal answer
beginner
What happens if the condition in a While loop is false at the start?
The code inside the While loop does not run at all because the condition is checked before the loop runs.
Click to reveal answer
beginner
Explain a real-life example of a Do-While loop.
Imagine you want to taste a soup and keep adding salt until it tastes right. You taste it first (run code), then decide if you need more salt (check condition). This is like a Do-While loop.
Click to reveal answer
In PowerShell, when does a While loop check its condition?
✗ Incorrect
A While loop checks the condition before running the code block each time.
Which loop guarantees the code runs at least once?
✗ Incorrect
A Do-While loop runs the code first, then checks the condition, so it always runs at least once.
What will happen if the While loop condition is false at the start?
✗ Incorrect
If the condition is false at the start, the While loop does not run at all.
Which symbol is used to increment a variable in PowerShell inside a loop?
✗ Incorrect
$i += 1 is the standard and compatible way to increment a variable by 1 in PowerShell.
What is the main purpose of loops like While and Do-While?
✗ Incorrect
Loops repeat a block of code multiple times based on a condition.
Describe how a While loop works in PowerShell and give a simple example.
Think about checking a rule before doing something repeatedly.
You got /3 concepts.
Explain the difference between While and Do-While loops with a real-life analogy.
Consider when you decide to repeat an action: before or after doing it once.
You got /3 concepts.