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

ios - Is 'init' forbidden as *part* of a variable name? -

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

file - Python: AttributeError: 'str' object has no attribute 'readlines' -