TAL Programmer's Guide
Scanning Arrays
Using Arrays
096254 Tandem Computers Incorporated 7–21
In the diagrams shown with the following examples, an arrow points to the character
that stopped the scan.
Scanning WHILE
SCAN WHILE searches until it finds a byte character other than the test character or a
zero. The following example scans left to right while spaces occur, starting from the
zeroth element of INT_ARRAY. The scan stops at the beginning of the last name and
stores that address in the next-address pointer START_LAST_NAME. An IF statement
then checks the carry bit to see what stopped the scan. If a character (rather than a
zero) stopped the scan, the program calls a string-handling procedure:
SCAN sptr[0] WHILE " " -> @start_last_name;
IF NOT $CARRY THEN
CALL string_handler;
Smith, Maurice
375
START_LAST_NAME
Scanning UNTIL
SCAN UNTIL searches until it finds the test character or a zero. The following
example scans INT_ARRAY left to right until it finds a comma or a zero, starting from
the address stored in START_LAST_NAME by the previous scan. If any character but
a comma stops the scan, the program calls an error-printing procedure:
SCAN start_last_name UNTIL "," -> @comma;
IF $CARRY THEN
CALL invalid_input;
Smith, Maurice
376
COMMA
Scanning Right to Left
The following RSCAN example finds the end of the last name. It scans INT_ARRAY
right to left for a character other than a space or a zero, starting from the location
preceding the comma. Because no space separates the end of the last name from the
comma, the scan starts and stops at the same location:
RSCAN comma[-1] WHILE " " -> @end_last_name;
Smith, Maurice
377
END_LAST_NAME