Return

Return[expr]

returns the value expr from a function.

Return[]

returns the value Null.

Details

  • Return[expr] exits control structures within the definition of a function, and gives the value expr for the whole function.
  • Return takes effect as soon as it is evaluated, even if it appears inside other functions.
  • Return can be used inside functions like Scan.

Examples

open allclose all

Basic Examples  (1)

Return from a function:

Possible Issues  (1)

Return exits only the innermost construct in which it is invoked:

Here it exits the Do loop, but not the function g:

Use Catch and Throw for explicit flow control:

Wolfram Research (1988), Return, Wolfram Language function, https://reference.wolfram.com/language/ref/Return.html (updated 1996).

Text

Wolfram Research (1988), Return, Wolfram Language function, https://reference.wolfram.com/language/ref/Return.html (updated 1996).

CMS

Wolfram Language. 1988. "Return." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 1996. https://reference.wolfram.com/language/ref/Return.html.

APA

Wolfram Language. (1988). Return. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Return.html

BibTeX

@misc{reference.wolfram_2024_return, author="Wolfram Research", title="{Return}", year="1996", howpublished="\url{https://reference.wolfram.com/language/ref/Return.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_return, organization={Wolfram Research}, title={Return}, year={1996}, url={https://reference.wolfram.com/language/ref/Return.html}, note=[Accessed: 21-December-2024 ]}