RETURN keyword

Welcome Forums General PowerShell Q&A RETURN keyword

This topic contains 1 reply, has 2 voices, and was last updated by

1 year, 9 months ago.

  • Author
  • #72274

    Points: 21
    Rank: Member

    In an interview Jeffrey Snover was asked:
    "Seeing the way PowerShell has evolved, what is your biggest regret?"
    He answered:
    "The return keyword was a misstep. Because any command output prior to return is also included, it doesn't behave intuitively.
    ..." ( )

    Can anybody explain this, with some examples?

  • #72275

    Points: 1,166
    Helping Hand
    Rank: Community Hero

    In other programming languages returns a function only what's specified with the key word "return". In Powershell a function returns everthing what's left in the "output channel".

    function Return-everything {
        'Simple string'
        'Another simple string'
        Return 'Return should only return what comes after the key word return, right?'

    This function in other languages would only return the content of the last line. Try it! 😉

The topic ‘RETURN keyword’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort