Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Return statement
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Syntax== Return statements come in many shapes. The following syntaxes are most common: {| class="wikitable" |- ! Language ! Return statement ! If value omitted, return |- | [[Ada (programming language)|Ada]], [[Bourne shell]],{{efn|in the Bourne shell, only integers in the range 0-255 may be returned<ref>{{cite web |url=https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#return |title=return - return from a function or dot script |work=Single UNIX Specification}}</ref>}} [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]], [[PHP]], [[C Sharp (programming language)|C#]], [[JavaScript]], [[D (programming language)|D]] | <syntaxhighlight lang="c">return value;</syntaxhighlight> | In the Bourne shell, exit value of the last command executed in the function In C<ref name=msc>{{cite web |url=https://learn.microsoft.com/en-us/cpp/c-language/return-statement-c |title=return Statement (C) |website=[[Microsoft Docs]]|date=25 January 2023 }}</ref> and C++,<ref name=mscpp>{{cite web |url=https://learn.microsoft.com/en-us/cpp/cpp/return-statement-cpp |title=return Statement (C++) |website=[[Microsoft Docs]] |date=3 August 2021 }}</ref> [[undefined behavior]] if function is value-returning In PHP,<ref>{{cite web|title=PHP: return - Manual |url=http://www.php.net/manual/en/function.return.php |work=PHP Manual |publisher=The PHP Group |access-date=26 March 2013 }}</ref> returns <code>NULL</code> In Javascript,<ref>{{cite web |title=Return - Javascript |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/return |work=MDN Javascript Reference |publisher=Mozilla Developer Network |access-date=27 March 2013 }}</ref> returns the value [https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/undefined <code>undefined</code>] In Java and C#, not permitted if function is value-returning |- | [[BASIC]] | <syntaxhighlight lang="qbasic">RETURN</syntaxhighlight> | |- | [[Lisp (programming language)|Lisp]] | <syntaxhighlight lang="lisp">(return value)</syntaxhighlight> | Last statement value |- | [[Perl]], [[Ruby (programming language)|Ruby]] | <syntaxhighlight lang="perl">return @values; return $value; return;</syntaxhighlight> or a contextual return sequence | Last statement value |- | [[PL/I]] | return(expression); return; | [[Undefined behavior]] if procedure is declared as returning a value |- | [[Python (programming language)|Python]] | <syntaxhighlight lang="python">return value</syntaxhighlight> | <code>None</code><ref name=python/> |- | [[Smalltalk]] | <syntaxhighlight lang="smalltalk">^ value</syntaxhighlight> | |- | [[Tcl]] | <syntaxhighlight lang="Tcl" class="nowrap">return return $value return -code error "Error message"</syntaxhighlight> or some more complicated combination of options | Last statement value |- | [[Visual Basic .NET]] | <syntaxhighlight lang="vbnet">Return value</syntaxhighlight> | |- | [[Windows PowerShell]] | <syntaxhighlight lang="ps1">return value;</syntaxhighlight> | Object |- | [[x86 assembly]] | <syntaxhighlight lang="asm">ret</syntaxhighlight> | Contents of eax register (by conventions) |} In some [[assembly language]]s, for example that for the [[MOS Technology 6502]], the mnemonic "RTS" (ReTurn from Subroutine) is used.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)