Se eu fizer o seguinte em um script do PowerShell:
$range = 1..100
ForEach ($_ in $range) {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Eu recebo a saída esperada de:
7 is a multiple of 7
14 is a multiple of 7
21 is a multiple of 7
28 is a multiple of 7
35 is a multiple of 7
42 is a multiple of 7
49 is a multiple of 7
56 is a multiple of 7
63 is a multiple of 7
70 is a multiple of 7
77 is a multiple of 7
84 is a multiple of 7
91 is a multiple of 7
98 is a multiple of 7
No entanto, se eu usar um pipeline e ForEach-Object
, continue
parece romper o loop do pipeline.
1..100 | ForEach-Object {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Posso ter um continue
comportamento semelhante enquanto ainda faço o ForEach-Object, para não precisar interromper meu pipeline?
foreach
: techotopia.com/index.php/...