Return statement
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is saved by the calling routine, today usually on the process's call stack or in a register. Return statements in many programming languages allow a function to specify a return value to be passed back to the code that called the function.
In computer programming, a return statement causes execution to leave the current subroutine and resume at the point in the code immediately after the instruction which called the subroutine, known as its return address. The return address is saved by the calling routine, today usually on the process's call stack or in a register. Return statements in many programming languages allow a function to specify a return value to be passed back to the code that called the function. ==Syntax== Return statements come in many shapes. The following syntaxes are most common: In some assembly languages, for example that for the MOS Technology 6502, the mnemonic "RTS" (ReTurn from Subroutine) is used. ==Yield statements== Cousin to return statements are yield statements: where a return causes a subroutine to terminate, a yield causes a coroutine to suspend. The coroutine will later continue from where it suspended if it is called again. Coroutines are significantly more involved to implement than subroutines, and thus yield statements are less common than return statements, but they are found in a number of languages. ==Call/return sequences== A number of call/return sequences are possible depending on the hardware instruction set, such as the following: The CALL instruction pushes address of the next instruction on the stack and branches to the specified address. The RETURN instruction pops the return address from the stack into the instruction pointer and execution resumes at that address. (Examples: x86, PDP-11) In architectures such as the Motorola 96000, the stack area may be allocated in a separate address space known as the Stack Memory Space, distinct from the main memory address space. The NEC μPD7720 also features a stack with its own separate address space. The CALL instruction places address of the next instruction in a register and branches to the specified address. The RETURN instruction sequence places the return address from the register into the instruction pointer and execution resumes at that address. (Examples: IBM System/360 and successors through z/Architecture, most RISC architectures) The CALL instruction places address of the next (or current ) instruction in the storage location at the call address and branches to the specified address+1. The RETURN instruction sequence branches to the return address by an indirect jump to the first instruction of the subroutine. (Examples: IBM 1130, SDS 9XX, PDP-8) ==See also== Return type Exit status ==Notes== ==References==
References
- ^ Wirth, Niklaus (May 3, 2016). "10. Procedure declarations". The Programming Language Oberon (PDF) (Report). p. 11. Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ "return - return from a function or dot script" . Single UNIX Specification . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ in the Bourne shell, only integers in the range 0–255 may be returned [ 11 ] Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ "PHP: return - Manual" . PHP Manual . The PHP Group . Retrieved 26 March 2013 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ "Return - Javascript" . MDN Javascript Reference . Mozilla Developer Network . Retrieved 27 March 2013 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Swartz, Fred. "C++ Notes: Function return Statement" . Archived from the original on 3 January 2007. Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Watt, David Anthony; Findlay, William (2004). Programming Language Design Concepts . John Wiley & Sons. pp. 215– 221. ISBN 978-0-470-85320-7 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Roberts, E. (March 1995). "Loop Exits and Structured Programming: Reopening the Debate" . ACM SIGCSE Bulletin . 27 (1): 268– 272. doi : 10.1145/199691.199815 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Martin Fowler; Kent Beck; John Brant; William Opdyke; Don Roberts (2012). Refactoring: Improving the Design of Existing Code (Google eBook) . Addison-Wesley. pp. 237, 250. ISBN 9780133065268 . ... one exit point mentality ... I don't follow the rule about one exit point from a method. Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Kent Beck (2007). "7: Behavior". Implementation Patterns . Pearson Education. section "Guard Clause". ISBN 9780132702553 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ "Multiple return statements" . Java Practices . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Fred Swartz. "Return statements and the single exit fantasy" . Archived from the original on 2020-02-23. Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ "The finally Block" . The Java Tutorials . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ "DSP96002 32-BIT Digital Signal Processor User's Manual" (PDF) . p. 3-4 . Retrieved 2023-12-24 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1703372400.0
- ^ "DSP96002 32-BIT Digital Signal Processor User's Manual" (PDF) . p. 4-11 . Retrieved 2023-12-24 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1703372400.0
- ^ "μPD77C20A, 7720A, 77P20 Digital Signal Processor" . p. 3a-4 . Retrieved 2023-12-25 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1703458800.0
- ^ Gleaves, R. (2012). Modula-2 for Pascal Programmers . Springer. p. 71. ISBN 9781461385318 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Flanders, Harley (2012). Scientific Pascal . Springer. p. 35. ISBN 9781461224280 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ ANSI x3.9-1966. USA Standard FORTRAN (PDF) . American National Standards Institute. p. 14. Archived from the original (PDF) on May 15, 2011 . Retrieved May 5, 2010 . {{ cite book }} : CS1 maint: numeric names: authors list ( link ) Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ ANSI x3.9-1978. American National Standard – Programming Language FORTRAN . American National Standards Institute. 15.8 RETURN Statement. Archived from the original on October 29, 2013 . Retrieved December 11, 2007 . {{ cite book }} : CS1 maint: numeric names: authors list ( link ) Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ Sakkinen, Markku (March 1989). "How to best return the value of a function" . ACM SIGPLAN Notices . 24 (3). Association for Computing Machinery: 55– 56. doi : 10.1145/66083.66087 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ a b "return Statement (C)" . Microsoft Docs . 25 January 2023. Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ a b "return Statement (C++)" . Microsoft Docs . 3 August 2021. Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ a b c Martelli, Alex (2006). Python in a Nutshell: A Desktop Quick Reference (2nd ed.). O'Reilly Media. p. 73. ISBN 9781449379100 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- ^ a b Scott, Michael L. (2006). Programming Language Pragmatics . Morgan Kaufmann. p. 432. ISBN 9780126339512 . Wikipedia revision 1359237580, retrieved 2026-11-22 · 1795302000.0
- Modula-2 for Pascal Programmers . · 1781305200.0
- return Statement (C++) . Microsoft Docs . 3 August 2021. · 1781305200.0
- PHP: return - Manual . PHP Manual . retrieved 26 March 2013 · 1781305200.0
- Return - Javascript . MDN Javascript Reference . · 1781305200.0
- - | Smalltalk | ^ value | |- | Tcl (programming language)|Tcl | return return $value return -code error "Error message" or some more complicated combination of options | Last statement value . · 1781305200.0
- Refactoring: Improving . · 1781305200.0
- Kent Beck. Implementation Patterns . Pearson Education . 2007. · 1781305200.0
- Multiple return statements . Java Practices . · 1781305200.0
- Fred Swartz. Return statements and the single exit fantasy . · 1781305200.0
- The finally Block . The Java Tutorials . · 1781305200.0
- DSP96002 32-BIT Digital Signal Processor User's Manual . retrieved 2023-12-24 · 1703372400.0
- Martelli, Alex. Python in a Nutshell: A Desktop Quick Reference . O'Reilly Media . 2006. · 1781305200.0
- μPD77C20A, 7720A, 77P20 Digital Signal Processor . · 1781305200.0
- Scott, Michael L. Programming Language Pragmatics . Morgan Kaufmann . 2006. · 1781305200.0
- Flanders, Harley. Scientific Pascal . Springer . 2012. · 1781305200.0
- USA Standard FORTRAN . · 1781305200.0
- American National Standard – Programming Language FORTRAN . · 1781305200.0
- Wirth, Niklaus. The Programming Language Oberon . May 3, 2016. · 1781305200.0
- while in JavaScript the value undefined is returned. In Windows PowerShell all evaluated expressions which are not captured (e.g., assigned to a variable, Type conversion|cast to Void type|v . · 1781305200.0
- return Statement (C) . Microsoft Docs . 25 January 2023. · 1781305200.0
Cite this
"Return statement". 1781392483. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1359237580