Se eseguo le operazioni seguenti in uno script PowerShell:
$range = 1..100
ForEach ($_ in $range) {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Ottengo l'output previsto di:
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
Tuttavia, se uso una pipeline e ForEach-Object
, continue
sembra uscire dal ciclo della pipeline.
1..100 | ForEach-Object {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Posso ottenere un continue
comportamento simile mentre continuo a eseguire ForEach-Object, in modo da non dover interrompere la mia pipeline?
foreach
: techotopia.com/index.php/…