If
$Variable = 6
if ($Variable -gt 5 ) {
Write-Host "Variable is greater than 5"
}
Variable is greater than 5
Else
$Variable = 4
if ($Variable -gt 5 ) {
Write-Host "Variable is greater than 5"
} else {
Write-Host "Variable is NOT greater than 5"
}
Variable is NOT greater than 5
Elseif
$Variable = 5
if ($Variable -gt 5 ) {
Write-Host "Variable is greater than 5"
} elseif ($Variable -eq 5) {
Write-Host "Variable is equal to 5"
} else {
Write-Host "Variable is NOT greater than 5"
}
For
for ($i = 1; $i -le 5; $i++) {
Write-Host "$i"
}
Foreach
$List = 1,2,3
foreach ($Number in $List) {
Write-Host "$Number"
}
While
while ($Number -ne 5) {
$Number++; Write-Host $Number
}
Do-While
$Place = 1
do {
Write-Host "I'm #$Place!"
} while ($Place -ne 1)