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

c# - Get the Class name in a class with atribute inside a attribute method -

java - How to compare two classes -

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