RETURN keyword

This topic contains 1 reply, has 2 voices, and was last updated by  Olaf Soyk 1 year ago.

  • Author
  • #72274


    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

    Olaf Soyk

    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! 😉

You must be logged in to reply to this topic.