October 2017
Intermediate to advanced
440 pages
11h 47m
English
do untiland 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 which are expected to be positive. For example, a script might wait for a computer to respond to 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 which are negative. For example, a ...
Read now
Unlock full access