do until and do while

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, a loop might wait for a remote computer to stop responding to a ping:

do { 
    Write-Host "Waiting for shutdown" 
    Start-Sleep -Seconds 5 
} while (Test-Connection 'SomeComputer' -Quiet -Count 1) 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.192.92