Do Until

The Do Until statement is the opposite of Do While statement.

This loop will execute your code until the condition is True. This means that the loop runs until while the condition is False.

Your code will also be executed at least 1 time before it checks the condition, this remains the same like the Do While statement.

Usage of do until

do {
	# your code here
} until (condition)
		

Examples

Count to 20:

$i = 1

do {
	Write-Host $i
	$i++
} until ($i -gt 20)
		

A shorter notation. Don't forget the semi-colon (;) delimiter here!

$i = 1

do {Write-Host $i; $i++}
until ($i -gt 20)
		

User input example, the .toUpper() method is not necessary because it will also stop if you just type yes instead of YES.

$response = "Quit"

do {
	$response = Read-Host "Are you sure you want to quit application? (YES/NO)"
} until ($response.toUpper() -eq "YES")