2.09 Branching and Linking

Labels

Labels may be defined anywhere within a program and may be used to identify the start of some code or the start of some data.

A label can be referenced by the goto and call statements, or by the data option on the put statement.

The format of a label is:

label:

The label can be any symbol name that is valid in Lynplex.

Implementation Status:

LynPlex Interpreter
Fully implemented
The keyword label is also supported to define a label but this is deprecated. It will be withdrawn in a future release.
LynPlexC Compiler
Fully implemented
LynPlexS Compiler
Fully implemented

Goto

The goto statement is used to branch or jump to another part of the code identified by a lable. There is no limitation on its use, but it should be used sparingly.

While using goto can help to make some programs run very quickly, the excessive use of goto statements can also make a program unmaintainable. It can be very difficult to find where a jump came from.

Syntax:

goto label

Example:

goto there
:
:
there:

Implementation Status:

All
Fully implemented

Call

Link to a specified position within the current procedure or function then return.

The return statement is used to return to the statement following the call.

Syntax:

call label
call subroutine

Example:

call my_routine
put "RETURN sent me here"
:
:
my_routine:
put "I am in my subroutine"
return
call my_sub
put "RETURN sent me here"
:
:
sub my_sub
put "I am in my subroutine"
end sub

Implementation Status:

LynPlex Interpreter
The call to a label is implemented.
The call to a subroutine is yet to be implemented.
LynPlexC Compiler
The call to a label is implemented.
The call to a subroutine is yet to be implemented.
LynPlexS Compiler
The call to a subroutine is implemented. return is not supported. The subroutine returns when it reaches the end or when an exit sub statement is found.
The call to a label is yet to be implemented.

Return

Returns from a call to a subroutine to the statement immediately following the most recent call command.

The return statement is also to used to return from a procedure or function. See 2.08 Procedures and Functions.

Syntax:

return

Implementation Status:

LynPlex Interpreter
Returns from a call to a label.
The call to a subroutine is yet to be implemented.
LynPlexC Compiler
Returns from a call to a label.
The call to a subroutine is yet to be implemented.
LynPlexS Compiler
Not yet supported. The subroutine returns when it reaches the end or when an exit sub statement is found. If a return statement is coded in a subroutine this has the effect of returning from the enclosing procedure or function.
The call to a label is yet to be implemented.

On goto|call (deprecated)

Branch to one of a list of labels. (deprecated)

Syntax:

on expr {goto|call} label1 [, …, labelN]

where:

expr
A numeric expression in the range 0 to 255. Upon execution of the ongoto command (or oncall), the program branches to the nth item in the list of labels that follows the keyword goto (or call).

Notes:

This command is deprecated. The limited function provided by this command can be carried out more flexibly by the select command. See 2.05 Selection.

Implementation Status:

LynPlex Interpreter
Not supported.
LynPlexC Compiler
Supported but is deprecated and will be removed in a future release.
LynPlexS Compiler
Supported but is deprecated and will be removed in a future release.

lynplex/lp0209.txt · Last modified: 2013/06/05 09:55 (external edit)