Skrevet av Emne: Powershell: continue does quite the opposite in a piped foreach loop  (Lest 4957 ganger)

Utlogget Floyd-ATC

  • Livstidsdiktator
  • Administrator
  • Guru
  • *****
  • Innlegg: 542
  • Karma: +12/-0
    • MSN Messenger - floyd@atc.no
    • Vis profil
    • floyd.atc.no
    • E-post
  • [applaud]0
  • [smite]0
  • 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



    -Floyd.

    --
    Det finnes 10 typer mennesker;
    de som forstår binærtall, de som ikke gjør det, og de som forstår Grey code.