Skip to content

Instantly share code, notes, and snippets.

@vexx32
Forked from JustinGrote/PowershellLoopBehavior.md
Last active January 15, 2022 10:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vexx32/65a6dad29a16fcc698645949c808540d to your computer and use it in GitHub Desktop.
Save vexx32/65a6dad29a16fcc698645949c808540d to your computer and use it in GitHub Desktop.
Reference Table for Loop Behavior in Powershell
Loop Return Continue Break
Normal Expectation Exit Scope Next Item Exit Loop
.foreach{} Next Item Break Scopes / Next Item of Parent Loop Break Scopes / Exit Parent Loop
foreach ($y in $x) Exit Scope Next Item Exit Loop
for ($i;$i -lt 5;$i++) Exit Scope Next Item Exit Loop
Foreach-Object -InputObject @() Next Item Break Scopes / Next Item of Parent Loop Break Scopes / Exit Parent Loop
Switch Exit Scope Next Item Exit Switch
While Exit Scope Next Item / Iteration Exit Loop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment