Si hago lo siguiente en un script de PowerShell:
$range = 1..100
ForEach ($_ in $range) {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Obtengo el resultado esperado 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
Sin embargo, si uso una tubería y ForEach-Object
, continue
parece romper el bucle de tubería.
1..100 | ForEach-Object {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
¿Puedo tener un continue
comportamiento similar mientras sigo haciendo ForEach-Object, para no tener que romper mi canalización?
foreach
: techotopia.com/index.php/…