NET/MASTER Network Control Language (NCL) Programmer's Guide
Calling Procedures and Functions
Procedures and Functions
6–44 106160 Tandem Computers Incorporated
The following example simulates a race between person A and person B to illustrate
procedure calling:
zex0622n: PROCEDURE
/* Race between person A and person B */
&a = 0 /* A starts from zero */
&b = 1 /* B gets a headstart */
CALL progress SHARE &a,&b /* Check headstart */
DO 7 /* Begin race */
&a = &a + RANDOM(1,6) /* A starts first */
CALL progress SHARE &a,&b /* Who's ahead now? */
&b = &b + RANDOM(1,6) /* B's turn */
CALL progress SHARE &a,&b /* Who's ahead now? */
END /* End race */
IF &a > &b THEN SAY "A wins by "&a - &b
IF &b > &a THEN SAY "B wins by "&b - &a
IF &a = &b THEN SAY "Draw"
EXIT
progress: PROCEDURE /* Check who's ahead */
SELECT
WHEN &a > &b THEN SAY "A is ahead by "&a - &b
WHEN &b > &a THEN SAY "B is ahead by "&b - &a
OTHERWISE SAY "Even"
END
END progress
END zex0622n
The PROGRESS procedure is called many times from inside a DO loop to check the
progress of the race.
The following screen shows the results of executing the procedure:
(13:56) --------------------- OPERATOR CONTROL SERVICES ----------------------
START ZEX0622N
B is ahead by 1
A is ahead by 4
Even
A is ahead by 2
B is ahead by 1
Even
B is ahead by 3
A is ahead by 1
B is ahead by 2
Even
B is ahead by 1
A is ahead by 5
A is ahead by 3
A is ahead by 5
A is ahead by 3
A wins by 3
NNM1005 START ZEX0622N PROCESSING COMPLETE. NCLID 001151
_____________________________________________________________________________
---------- ------------------ NonStop NET/MASTER D30 ---------------- --------
M=>