{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Return Statements

Return Statements - The function body A function call...

Info icon This preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Return Statements Execution of a return statement terminates execution of the method body and, hence, of the method call. The return statement in the body of a function differs from the return statement in a procedure or constructor. See below. The procedure and constructor bodies When a procedure or constructor is called, the statements in its body are executed one at a time, in the order in which they appear. During this execution, execution of the statement: return; terminates execution of the body, and thus of the procedure or constructor call —no further statement in the body is executed, once a return-statement is executed. A return- statement need not be included in the body of a procedure or constructor, but sometimes a body may be easier to write using a return-statement.
Image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The function body A function call yields a value. Therefore, execution of a function body must terminate by executing a return-statement of the form return <expression> ; where the type of the <expression> is the same as (or narrower than) the type of the result of the function. Execution of such a return-statement terminates the function body, and, thus, the function call, and yields the value of the<expression> as the result of the call. Since execution of a function body must terminate with execution of a return-statement, the last statement of a function body is usually a return-statement. However, return-statements may appear in other places as well. ©2005 Cornell University...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern