Return behavior in PowerShell

suggest change

Introduction

It can be used to Exit the current scope, which can be a function, script, or script block. In PowerShell, the result of each statement is returned as output, even without an explicit Return keyword or to indicate that the end of the scope has been reached.

Remarks

You can read more about the return semantics on the about_Return page on TechNet, or by invoking get-help return from a PowerShell prompt.


Notable Q&A question(s) with more examples/explanation:


about_return on MSDN explains it succinctly:

The Return keyword exits a function, script, or script block. It can be used to exit a scope at a specific point, to return a value, or to indicate that the end of the scope has been reached.

Users who are familiar with languages like C or C# might want to use > the Return keyword to make the logic of leaving a scope explicit.

In Windows PowerShell, the results of each statement are returned as > output, even without a statement that contains the Return keyword. > Languages like C or C# return only the value or values that are > specified by the Return keyword.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents