Concept Flow - Why control flow directs execution
Start script
Evaluate condition
Run block
Continue to next step
End
Control flow checks conditions and decides which code parts run next, guiding the script step-by-step.
if ($x -gt 5) { Write-Output "Greater" } else { Write-Output "Smaller or equal" }
| Step | Condition Evaluated | Condition Result | Branch Taken | Output |
|---|---|---|---|---|
| 1 | $x -gt 5 | True | If block | Greater |
| 2 | End of script | - | - | - |
| Variable | Start | After Step 1 | Final |
|---|---|---|---|
| x | 7 | 7 | 7 |
Control flow uses conditions to guide which code runs. If condition is True, run the 'if' block. If False, run the 'else' block if present. This directs script execution step-by-step. Without control flow, scripts run straight top to bottom.