Teknisk > Generelt teknisk
Powershell: continue does quite the opposite in a piped foreach loop
(1/1)
Floyd-ATC:
In these two code snippets, the "continue" keyword does quite the opposite of what it's supposed to:
--- Kode: ---PS C:\> ('a','b','c') | % { $_; continue }
a
--- Slutt kode ---
--- Kode: ---PS C:\> ('a','b','c') | foreach { $_; continue }
a
--- Slutt kode ---
When spelling the code out like you would in a sane scripting language, it works as expected:
--- Kode: ---PS C:\> foreach ($i in ('a','b','c')) { $i; continue }
a
b
c
--- Slutt kode ---
Go figure.
--- Kode: ---PS C> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
4 0 -1 -1
--- Slutt kode ---
Navigering
[0] Oversikt
Skift til full visning