POwerShell supports three types of While and Do loops:
- While loops
- Do... While loops
- Do ... Until loops
- While True loops
Example: Do ... While Loop
$i=1
Do {
$i
$i++
}
While ($i -le 5)
Output:
1
2
3
4
5
Example: Do .. Until Loop
$i=1
Do {
$i
$i++
}
Until ($i -gt 5)
Output:
1
2
3
4
5
Example: While Loop
$i=1
While ($i -le 5)
{
$i
$i++
}
Output:
1
2
3
4
5
Example: While True Loop
$i=1
While ($true)
{
$i
$i++
if ($i -gt 5) {
Break
}
}
Output:
1
2
3
4
5