BREAK in nested Loops behaves weird


i found weird behavior of break in nested loops.

here test-code:

#1   :outerloop foreach ($x in 1..3) {     'x' + $x     :innerloop foreach ($y in 1..8) {        ' y' + $y        if ($y -ge 5) {           break innerloop        }     }  }      #2  :outerloop foreach ($x in 1..3) {     'x' + $x     :innerloop foreach ($y in 1..8) {        ' y' + $y        if ($y -ge 5) {           break noloop        }     }  }  

#1 breaks inner loop expected.

#2 breaks outer loop though specified not-existing label "noloop" break. expect error or warning. @ worst expect non-existing label ignored and the outer loop breaks.

does see logic behind behavior?



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2