Forums.ATC.no

Teknisk => Generelt teknisk => Emne startet av: Floyd-ATC på 21. ſeptember 2016, 15:29 pm

Tittel: Powershell: continue does quite the opposite in a piped foreach loop
Skrevet av: Floyd-ATC21. ſeptember 2016, 15:29 pm
In these two code snippets, the "continue" keyword does quite the opposite of what it's supposed to:
Kode: [Velg]
PS C:\> ('a','b','c') | % { $_; continue }
a
Kode: [Velg]
PS C:\> ('a','b','c') | foreach { $_; continue }
a

When spelling the code out like you would in a sane scripting language, it works as expected:
Kode: [Velg]
PS C:\> foreach ($i in ('a','b','c')) { $i; continue }
a
b
c

Go figure.
Kode: [Velg]
PS C> $PSVersionTable.PSVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
4      0      -1     -1