Si je fais ce qui suit dans un script PowerShell:
$range = 1..100
ForEach ($_ in $range) {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
J'obtiens la sortie attendue 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
Cependant, si j'utilise un pipeline et ForEach-Object
, continue
semble sortir de la boucle du pipeline.
1..100 | ForEach-Object {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Puis-je avoir un continue
comportement de type-like tout en faisant ForEach-Object, pour ne pas avoir à interrompre mon pipeline?
foreach
: techotopia.com/index.php/…