contents.gifprev1.gifnext1.gif

Statements

nu/TPU programs consist of a sequence of declarations and statements that follow the nu/TPU language syntax.

ABORT Statement

The ABORT statement tells nu/TPU to stop whatever it’s doing and return control to the screen manager algorithm. ABORT doesn’t instruct nu/TPU to stop processing altogether and return to the operating system, but it does tell nu/TPU to stop running the current procedures. In other words, any routine or routines which you have instructed nu/TPU to execute are terminated and you’re returned to the current nu/TPU main control loop, at which point nu/TPU waits for the next keystroke. The ABORT statement is most commonly used in procedure error handlers. The command syntax is:

ABORT;

Note that the semicolon (;) is optional; its use is based on context. A simplified example of ABORT follows:

PROCEDURE READ_CHAR_TEST

ON_ERROR

message (“unknown program error!”);

ABORT;

ENDON_ERROR

!

read_line (‘Enter_text’);

ENDPROCEDURE

ASSIGNMENT Statement

The assignment statement assigns a value to a variable. If the variable does not exist, it is created during the assignment process. Any valid nu/TPU data type can be assigned to a variable. When an existing variable is assigned a new value, its data type may also change.

Syntax:

variable := expression;

Example:

my_variable := 123;

my_variable := ‘text string’;

The first line creates a new variable with an integer data type and a value of 123. The second line not only changes the value of the variable but its data type also changes to string.

CASE...FROM...TO...INRANGE...OUTRANGE...

OTHERWISE...ENDCASE Statement

The CASE statement and its various qualifiers can provide a robust conditional processing block of code. The form of the CASE statement is:

CASE expression

{FROM low_value TO high_value}

[value]:statement {,...};

[value n]:statement n {,...};

[INRANGE]:statement {,...};

[OUTRANGE]:statement {,...};

[OTHERWISE]:statement {,...};

ENDCASE;

Note: The square brackets ([]) around the case constants, INRANGE, and OUTRANGE are not optional. Elements within the braces ({}) are optional. This is a deviation from the standard documentation syntax.

Not all the qualifiers need to be used in a given CASE code block.

CASE requires some initial variable to be evaluated. This is shown at the start of the code block by the line:

CASE expression

The variable to be evaluated can be any valid nu/TPU data type. The evaluation of that variable occurs in the lines up until the last statement of the code block, ENDCASE. All evaluations occur between the opening CASE and the closing ENDCASE, whether those evaluations are implied or explicit.

CASE i

FROM 0 TO 1

[0]: x := “You typed ‘0’.”;

[1]: x:= “You typed ‘1’.”;

ENDCASE;

The FROM, TO, INRANGE, OUTRANGE, and OTHERWISE qualifiers are optional.

The optional FROM qualifier is used to set a base for evaluating the CASE expression.

The optional TO qualifier is used to set a ceiling for evaluating the CASE expression.

You can use FROM without TO and TO without FROM. However, if you’re going to use both, the FROM qualifier must come before TO. CASEs to be tested for are included in brackets ([]). This is necessary regardless of whether you use FROM, TO, or FROM...TO.

INRANGE only handles those occurrences of the input variable which are between FROM and TO, but are not explicitly handled by any of the other evaluation values.

OUTRANGE handles those occurrences of the input variable which are below FROM and above TO. OTHERWISE handles those occurrences of the input variable which are not explicitly handled by the evaluation values.

You can create multiple explicit evaluation values by using commas (,) to separate the explicit values. An example of this would be:

[0, 1]: x:= “You typed either 0 or 1.”;

In the above, both 0 and 1 cause nu/TPU to respond with the same result. Note that multiple evaluation values must be separated by commas.

You can also place multiple command lines for each evaluation by separating one command line from another with a semi-colon (;). The following is an example.

[1]: x := “You typed 1";

copy_text (“Anything else while I’m here?”);

update (current_window);

[2]: x:= “You typed 2";

IF...THEN...ELSE...ENDIF

The nu/TPU IF...THEN...ELSE...ENDIF code block is a method for evaluating Boolean algebra inside a program or procedure. Like all Boolean operations, the IF...THEN...ELSE...ENDIF can handle only two possibilities: true/false. The syntax is:

IF condition

THEN

statement;...

ELSE (the condition was false)

statement;...

ENDIF

Note: When evaluating the Boolean expression, odd numbers evaluate to true and even numbers evaluate to false. The ON_ERROR nu/TPU statement cannot be used within the THEN or ELSE conditions.

Conditional Compilation

The keywords and syntax for conditional compilation are very similar to our traditional IF...THEN...ELSE...ENDIF syntax.

Syntax:

%IFDEF variable

%THEN

statements;...

[%ELSE statement;...]

%ENDIF;

%IF expression

%THEN

statements;...

[%ELSE statement;...]

%ENDIF;

When the %IF expression is evaluated to true, the code in the %THEN block is compiled, otherwise the optional code from the %ELSE block is compiled. In the first format, we must remember that the expression must be a Boolean expression, thus always evaluating to true or false. The second format, which uses a program identifier, needs additional clarification. If the identifier in the %IFDEF statement is defined, code in the %THEN block is compiled. The value or data type of the identifier does not affect the evaluation of %IFDEF. The %IFDEF tests simply to see if the identifier is defined. Remember that procedure names are valid identifiers.

LOOP...EXITIF...ENDLOOP

The basic LOOP...ENDLOOP structure is used for recursive operations. Once the EXITIF expression evaluates to TRUE, the loop processing is ended.

Syntax:

LOOP

[statement; [...]];

EXITIF expression;

[statement; [...]];

ENDLOOP;

The LOOP statement must contain at least one EXITIF clause. All the statements with the LOOP statement are executed repeatedly until the expression in an EXITIF clause evaluates as true (an odd number) or if one of the LOOP body statements is either an ABORT or RETURN statement.

Example

! Kindergarten counter

fingers := 1;

LOOP

EXITIF fingers = 10;

fingers := fingers + 1;

ENDLOOP;

RETURN Statement

RETURN is used to stop processing in the current procedure and return control to the calling procedure or screen manager/user input loop. The form is:

RETURN [value]

In the above, “value” is an optional parameter which is evaluated and returned to the calling routine.

Example

RETURN “This is the end”;