# CHAIN

Updated: 11/30/2021, 7:00:45 PM
Created: 11/30/2021, 7:00:45 PM
Last Updated By: Jake Tuttle
Read Time: 1 minute(s)

# Description

The CHAIN statement exits the current program and transfers process control to the program defined by the expression. Process control will never return to the originating program. The statement takes the form:

CHAIN expression {(I}
1

Where expression should evaluate to a valid UNIX or Windows command, which may be another jBASE BASIC program.

The command string may be suffixed with the ‘I’ option, which will cause any COMMON variables in the current program to be inherited by the new program (providing it is a jBASE BASIC program).

# Note

There are no restrictions to the CHAIN statement. However, it is advisable that your program follows a logical path easily seen by another programmer.

If the program, which contains the CHAIN command (the current program) was called from a jCL program, and the program to be executed (the target program) is another jBASE BASIC program, control will return to the original jCL program when the target program terminates. If the target program is a jCL program, control will return to the command shell when the jCL program terminates.

# Examples

CHAIN "OFF" ;* exit via the OFF command
1

Consider two programs as:

PROGRAM Prog1
COMMON varA, varB
varA = 50;
varB = 100
CHAIN "newPROG (I"
1
2
3
4
5
PROGRAM newPROG
COMMON varI, varJ
* varI and varJ inherited
CRT varI, varJ
1
2
3
4

running Prog1 will result in:

50      100
1

being displayed.

Go back to jBASE BASIC

Go back to Programmers' Reference Guide