February 2019
Intermediate to advanced
626 pages
15h 51m
English
do until and do while each execute the body of the loop at least once, as the condition test is at the end of the loop statement. Loops based on do until will exit when the condition evaluates to true; loops based on do while will exit when the condition evaluates to false.
do loops are written using the following notation:
do {
<body-statements>
} <until | while> (<condition>)
do until is suited to exit conditions that are expected to be positive. For example, a script might wait for a computer to respond to a ping:
do {
Write-Host "Waiting for boot"
Start-Sleep -Seconds 5
} until (Test-Connection 'SomeComputer' -Quiet -Count 1)
The do while loop is more suitable for exit conditions that are negative. For example, ...
Read now
Unlock full access