about_While - PowerShell


 

Describes a language statement that you can use to run a command block (about_While)

   
# TOPIC
about_While

# SHORT DESCRIPTION
Describes a language statement that you can use to run a command block
based on the results of a conditional test.

# LONG DESCRIPTION
The While statement (also known as a While loop) is a language construct
for creating a loop that runs commands in a command block as long as a
conditional test evaluates to true. The While statement is easier to
construct than a For statement because its syntax is less complicated.
In addition, it is more flexible than the Foreach statement because you
specify a conditional test in the While statement to control how many times
the loop runs.

The following shows the While statement syntax:

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

When you run a While statement, Windows PowerShell evaluates
the <condition> section of the statement before entering the
<statement list> section. The condition portion of the statement resolves
to either true or false. As long as the condition remains true, Windows
PowerShell reruns the <statement list> section.

The <statement list> section of the statement contains one or more commands
that are run each time the loop is entered or repeated.

For example, the following While statement displays the numbers 1
through 3 if the $val variable has not been created or if the $val variable
has been created and initialized to 0.

while($val -ne 3)
{
$val++
Write-Host $val
}

In this example, the condition ($val is not equal to 3) is true while
$val = 0, 1, 2. Each time through the loop, $val is incremented by 1
using the ++ unary increment operator ($val++). The last time through
the loop, $val = 3. When $val equals 3, the condition statement
evaluates to false, and the loop exits.

To conveniently write this command at the Windows PowerShell command
prompt, you can enter it in the following way:

while($val -ne 3){$val++; Write-Host $val}

Notice that the semicolon separates the first command that adds 1 to
$val from the second command that writes the value of $val to the
console.

SEE ALSO
about_Comparison_Operators
about_Foreach
about_For

C:\Windows>powershell get-help about_wildcards -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

... facebook.de
... Windows-10 FAQ
... Windows-10 Info


Become a Sponsor
... Your button here?





PowerShell: Describes a language statement that you can use to run a command block

HTTP: ... PS_Windows/en/about_While.htm
0.249
13190

Vorschau im Film-Streifen Modus und Datei Details!

 /

Opening the PC settings under Windows 10 - 3 options!

 /

Dateiformate und Dateitypen, was ist das?

 /

Can I Paste plain text from the clipboard via placeholder?

 /

Can i uninstall Find.Same.Images.OK from Windows 10, 8.1 or 7?

 /

Download Windows 10 all Version with Windows MediaCreationTool?

 /

Copy Windows 8.1 and 10 directory view settings for all directorys, (match, transfer)?

 /

Windows 10 start famous fax and scan feature!

 /

Individuelle Spalte speichern plus Datei-Explorer Ansichten unter Win 10, 8.1, ...!

 /

Unicode, oder (x64) 64-Bit, oder x32/x86 (32-Bit)?

 /

Wozu Öffnen, Schließen der Laufwerk oder DVD Auswerfen, USB, CD, Blue-Ray?

 /

How can i enable/switch on Windows 8 and Win 8.1 to the 1680x1050 screen resolution?

 /