Scan Parts with Count Parts

FOR <count part> WHILE <relational operator> <arithmetic expression>

The stack-integer-counter is initialized to the value of the arithmetic expression in the count part. Characters are then scanned and the stack-integer-counter is decremented for each character as long as the stack-integer-counter is not zero and a source character passes the test.

For example, the following statement scans the first 20 characters pointed to by P as long as a period (.) is not encountered:

SCAN P FOR N:20 WHILE NEQ "."

Because N reflects how many of the 20 characters have yet to be scanned, it can be used to determine whether a period was encountered and, if so, where the period is.

FOR <count part> UNTIL <relational operator> <arithmetic expression>

The stack-integer-counter is initialized to the value of the arithmetic expression in the count part. Characters are then scanned and the stack-integer-counter is decremented for each character until either the stack-integer-counter is zero or a source character passes the test. For example, the following statement scans the first N characters pointed to by P until the first nonblank character is encountered:

SCAN P:P FOR N:N UNTIL NEQ " "

If, when the statement is invoked, the value of N is the number of characters between P and the end of the array row, then because both P and N are updated in this statement, at the completion of the statement, N gives the number of characters between the updated P and the end of the array row.

FOR <count part> WHILE IN <truth set table>

The stack-integer-counter is initialized to the value of the arithmetic expression in the count part. Characters are then scanned and the stack-integer-counter is decremented for each character as long as the stack-integer-counter is not zero and source characters are members of the truth set. For further information on truth sets, see TRUTHSET Declaration.

For example, the following statement scans the first 20 characters pointed to by P as long as they are members of the truth set ALPHA8:

SCAN P:P FOR N:20 WHILE IN ALPHA8

P is updated to point to the first character that is not a member of ALPHA8, or, if all of the 20 characters scanned are members of ALPHA8, to the character that is 20 characters beyond the initial position of P. N is assigned the number of characters yet to be scanned.

FOR <count part> UNTIL IN <truth set table>

The stack-integer-counter is initialized to the value of the arithmetic expression in the count part. Characters are then scanned and the stack-integer-counter is decremented for each character until either the stack-integer-counter is zero or a source character is a member of the truth set. For further information on truth sets, see TRUTHSET Declaration.

For example, the following statement scans the first 20 characters pointed to by P until a member of the truth set ALPHA8 is encountered:

SCAN P:P FOR 20 UNTIL IN ALPHA8

P is updated to point to the first character that is a member of ALPHA8, or, if none of the 20 characters scanned are members of ALPHA8, to the character that is 20 characters beyond the initial position of P.