TAL Programmer's Guide

Scanning Arrays
Using Arrays
096254 Tandem Computers Incorporated 7–19
When the preceding example executes, LINE_ARRAY contains the following:
DATE: Feb 1, 1992 ID NUMBER: 854-70-1950 DEPARTMENT: 107
Initializing a Large Array Quickly
To initialize a large array quickly, you can concatenate two copy operations in a move
statement. The first copy operation copies two spaces into element [0], and the second
copies the spaces from element [0] into the remaining elements:
LITERAL length = 100; !Length of array
INT .array[0:length - 1]; !Destination array
array[0] ':=' " " & array[0] FOR (length - 1);
!Initialize array to blanks
In the preceding example, make sure the value in the FOR clause is a positive number.
The move statement treats the value as an unsigned integer. It treats a small negative
number (such as –1) as a large positive number (in this case, 65,535).
Scanning Arrays You can use scan statements to scan arrays for a test character. You can apply scan
statements to any array (except UNSIGNED arrays) located in the lower 32K-word
area of the user data segment or no more than 32K words away in the user code
segment. You can only scan bytes.
The SCAN statement scans an array from left to right. The RSCAN statement scans an
array from right to left. Both scan statements return the next address, described in
“Using the Next Address” earlier in this section.
Delimiting the Scan Area Unless you delimit the scan area, a scan operation might continue to the 32K-word
boundary if:
A SCAN UNTIL operation does not find a zero or the test character
A SCAN WHILE operation does not find a zero or a character other than the test
character
When you declare the array to scan, you can use zeros to delimit the start and end of
the scan area. Here is an example for delimiting the scan area with zeros:
INT .buffer[-1:20] := [0," John James Jones ",0];
Here is another example for delimiting the scan area with zeros:
LITERAL stopper = 0;
STRING an_array[0:9];
!Fill array from some source
an_array[0] := stopper;
an_array[9] := stopper;