Conditions for continuing and terminating loops
Do-while () will be executed before you can make sure that the loop executes at least once.
Copy Code code as follows:
PS c:powershell> do {$n =read-host} while ($n-ne 0)
10
100
99
2012
The end of the world
Why don't you quit?
Because the condition is not satisfied
How to meet
Please enter a 0, try
0
PS c:powershell>
Use while in isolation
Copy Code code as follows:
$n =5
while ($n-GT 0)
{
$n
$n = $n-1
}
5
4
3
2
1
Terminate the current loop
Use the Continue keyword, but terminate the current loop, skip the other statements after continue, and recycle again.
Copy Code code as follows:
$n =1
while ($n-lt 6)
{
if ($n-eq 4)
{
$n = $n +1
Continue
}
Else
{
$n
}
$n = $n +1
}
1
2
3
5
Jump out of the loop statement
Use the break keyword to jump out of a loop statement
Copy Code code as follows:
$n =1
while ($n-lt 6)
{
if ($n-eq 4)
{
Break
}
$n
$n + +
}