about_Break.help - TOPIC about_Break SHORT DESCRIPTION...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 TOPIC about_Break SHORT DESCRIPTION Describes a statement you can use to immediately exit Foreach, For, While, Do, or Switch statements. LONG DESCRIPTION When a Break statement appears in a loop, such as a Foreach, For, Switch, or While loop, the Break statement causes Windows PowerShell to immediately exit the loop. In a Switch construct that does not loop, Break causes Windows PowerShell to exit the Switch code block. A Break statement can include a label that lets you exit embedded loops. A label can specify any loop keyword, such as Foreach, For, or While, in a script. When you use a label, Break exits the specified loop. Break exits the specified loop, regardless of which loop the Break statement is in. The following example shows how to use a Break statement to exit a For statement: for($i=1 $i -le 10 $i++) { Write-Host $i break } In this example, the Break statement exits the For loop when the $i variable equals 1. Even though the For statement evaluates to True until $i is greater than 10, Windows PowerShell reaches the break statement the first time the For loop is run. It is more common to use the Break statement in a loop where an inner condition must be met. Consider the following Foreach statement example: $i=0 $varB = 10,20,30,40 foreach ($val in $varB) { $i++ if ($val -eq 30) { break } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

about_Break.help - TOPIC about_Break SHORT DESCRIPTION...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online