syntax - continue statement confusing in powershell, looks like break statement -


my code looks like:

1..10 | % {     $i=$_     10..20 | % {         if ($_ -gt 12) {             continue         }        write-host $i $_     } } 

why output is:

1 10 1 11 1 12 

it seems continue statement in poweshell not different other language, why powershell designed this?

if change continue return, expect result.

as peterserai pointed out in comment, don't use loop in code, instead using foreach-object cmdlet different.

just use foreach loop instead:

foreach($obj in 1.. 10) {     $i = $obj     foreach($obj2 in 10 ..20) {         if ($obj2 -gt 12) {             continue         }        write-host $obj $obj2     } } 

Comments

Popular posts from this blog

android - Basic camera in app -

javascript - Why Selenium can't find an element that is graphically visible -

scala - Using the kronecker product on complex matrices with scalaNLP breeze -