# return statement

The return statement terminates an internal or external subroutine,
 and returns execution control to the statement following the invoking call or
 gosub statement.

## Syntax

```
return
return {to statement.label}
```

## Parameter(s)

| statement.label | Specifies the statement to which control is returned. |
| --- | --- |
| return_value | The return_value terminates an internal or external function, and returns execution control to the statement following the invoking call or gosub statement. Required if returning from a user-defined function (deffun statement) as opposed to a local sub-routine call or remote sub-routine call. |
**For Windows:** Locally defined variables in external subroutines (and files opened to local
 file variables) are automatically abandoned or closed on return.

## Description

The to clause
can only be used with an internal subroutine, and transfers control
to the specified statement label. This is not a recommended programming
practice.

Note: If the subroutine was executed from TCL, the *return_value* exits the
 subroutine and returns to TCL.

## Example(s)

**Example 1:**

 If the answer is y, then call internal subroutine 1000. When 1000 is
 complete, control is returned to the line that prints back again.

```
input answer
if answer = ’y’ then gosub 1000
print ’back again’
stop
1000 * subroutine
print ’ok’
return
```

 **Example 2:**

 function is compatible with other PICK vendors. You can also use
 sub. In this example, nCube is the return
 value.
```
fnCube
001 function fnCube(px);
002 nCube=px*px*px
003 return nCube
```

## See also

- [call statement](https://d3codex.com/pickbasic-flashbasic/call-statement/)
- [deffun statement](https://d3codex.com/pickbasic-flashbasic/deffun-statement/)
- [function statement](https://d3codex.com/pickbasic-flashbasic/function-statement/)
- [gosub statement](https://d3codex.com/pickbasic-flashbasic/gosub-statement/)
- [on...gosub statement](https://d3codex.com/pickbasic-flashbasic/on-gosub-statement/)
- [statement labels](https://d3codex.com/pickbasic-flashbasic/statement-labels/)
- [subroutine statement](https://d3codex.com/pickbasic-flashbasic/subroutine-statement/)

---
Source: https://d3codex.com/pickbasic-flashbasic/return-statement/ - part of the D3Codex reference.
