Runs a statement list one or more times, subject to a While or Until (about_do)

   
# TOPIC
about_Do

# SHORT DESCRIPTION
Runs a statement list one or more times, subject to a While or Until
condition.

# LONG DESCRIPTION
The Do keyword works with the While keyword or the Until keyword to run
the statements in a script block, subject to a condition. Unlike the
related While loop, the script block in a Do loop always runs at least
once.

A Do-While loop is a variety of the While loop. In a Do-While loop, the
condition is evaluated after the script block has run. As in a While loop,
the script block is repeated as long as the condition evaluates to true.

Like a Do-While loop, a Do-Until loop always runs at least once before
the condition is evaluated. However, the script block runs only while
the condition is false.

The Continue and Break flow control keywords can be used in a Do-While
loop or in a Do-Until loop.

Syntax
The following shows the syntax of the Do-While statement:

do {<statement list>} while (<condition>)

The following shows the syntax of the Do-Until statement:

do {<statement list>} until (<condition>)

The statment list contains one or more statements that run each time
the loop is entered or repeated.

The condition portion of the statement resolves to true or false.

Example
The following example of a Do statement counts the items in an
array until it reaches an item with a value of 0.

C:\PS> $x = 1,2,78,0
C:\PS> do { $count++; $a++; } while ($x[$a] -ne 0)
C:\PS> $count
3

The following example uses the Until keyword. Notice that
the not equal to operator (-ne) is replaced by the
equal to operator (-eq).

C:\PS> $x = 1,2,78,0
C:\PS> do { $count++; $a++; } until ($x[$a] -eq 0)
C:\PS> $count
3

The following example writes all the values of an array, skipping any
value that is less than zero.

do
{
if ($x[$a] -lt 0) { continue }
Write-Host $x[$a]
}
while (++$a -lt 10)

SEE ALSO
about_While
about_Operators
about_Assignment_Operators
about_Comparison_Operators
about_Break
about_Continue

C:\Windows>powershell get-help about_environment_variables -full

ColorConsole [Version 1.7.1000] PowerShell 2.0-Export
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2014 Microsoft Corporation.

OS: Windows 10, 8.1, 8, 7, Vista / Windows Server 2016, 2012, 2008
»»»» ColorConsole









... Windows-10




Windows 10 How To

... Windows 10 FAQ
... Windows 10 How To




PowerShell: Runs a statement list one or more times, subject to a While or Until

HTTP: ... PS_Windows/en/about_do.htm
0.187
12308

Who needs this Pixel Tester for Windows (10, 8.1, 7, or 11)?

 /

Where does the desktop clock save the settings on MS Windows 10/11?

 /

How to disable Windows Shadows on Windows 10, 8.1?

 /

Use computer name and user name in Quick Text Paste!

 /

Hilfe Windows 11 hat keinen Gerätemanager, warum?

 /

Help, where can i turn off the Windows 8 or 8.1, or shut down the MS Windows OS?

 /

DEP - Datenausführungsverhinderung  in Windows 8.1 und 10 aktivieren, oder deaktivieren!

 /

KeepMouseSpeedOK to keep the Mouse Speed on all Windows (11, 10, ...)!

 /

Standby, hibernation or lock in the start menu!

 /

Schrifttyp, bzw. Schriftart am Android Handy ändern?

 /

What is scrolling?

 /

HP Laserjet III, 4, 5, Plus, Driver x64, x32, Windows 11, 10, 8.1, 7, ...!

 /