Introduction
Control flow tells the script what to do next. It helps decide which parts run and when, so your script works step by step.
if (<condition>) { # code to run if condition is true } elseif (<another condition>) { # code if second condition is true } else { # code if no conditions are true } while (<condition>) { # code to repeat while condition is true } for (<init>; <condition>; <change>) { # code to repeat with a counter }
if ($age -ge 18) { Write-Output "You can vote." } else { Write-Output "You are too young to vote." }
while ($count -lt 5) { Write-Output "Count is $count" $count++ }
for ($i = 1; $i -le 3; $i++) { Write-Output "Number $i" }
$number = 7 if ($number -gt 10) { Write-Output "Number is greater than 10" } elseif ($number -eq 7) { Write-Output "Number is exactly 7" } else { Write-Output "Number is 10 or less and not 7" }
for ($i = 1; $i -le 3; $i++) { if ($i -eq 2) { continue } Write-Output $i }if $x -gt 10 { Write-Output 'Big' }$count = 0
while ($count -lt 5) {
$count++
if ($count -eq 3) { continue }
Write-Output $count
}
Pass the test and this pattern moves unknown