Return statement

It returns control of execution to the caller.


Table of contents:


Format

return

Expression

Semicolon

Example

Format

The format are:


return ;

return expression ;


Execution is stopped by the return statement. And execution control is returned to the caller.

If there is an expression after the return keyword, the instance generated by the expression is returned to the caller. The class of the expression must match the class of the member's return value.

If there is no expression, an instance of the void class is returned.

return

A keyword that indicates that it is a return statement.

Expression

Generates an instance that will be returned to the caller. If there is no return value, it can be omitted.


The class of the returned instance must match the return type of the member.

The return statement must not return a value if the calling member does not return a value or void is specified.

Semicolon

The end of a return statement is represented by a semicolon.

Example

1:

class example

2:

open getter string URL

3:

return "http://example.com/";

4:

eg

5:

ec

1:

example ex;

2:

string url = ex.URL;

Copyright © Rice All rights reserved.