Do until and do while

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