Jika saya melakukan hal berikut dalam skrip PowerShell:
$range = 1..100
ForEach ($_ in $range) {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Saya mendapatkan hasil yang diharapkan dari:
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
Namun, jika saya menggunakan pipa dan ForEach-Object
, continue
tampaknya untuk keluar dari lingkaran pipa.
1..100 | ForEach-Object {
if ($_ % 7 -ne 0 ) { continue; }
Write-Host "$($_) is a multiple of 7"
}
Bisakah saya mendapatkan continue
perilaku -seperti saat masih melakukan ForEach-Object, jadi saya tidak perlu memutuskan pipeline saya?
foreach
: techotopia.com/index.php/…