Previous Topic: An Example of the COMPARE CommandNext Topic: Compare Two Strings


Compare Value of an Accumulator with an Integer

ACL/E can also compare the value of an accumulator with a positive integer. For example, you can rewrite the program that compares the values of accumulators A1 and A2 to compare the value of A1 and the integer 10. The following is an example of such a program:

           SET A1,10 
           COMPARE A1,10 
           BRANCH EQ,EQUAL 
           KEY 'A1 does not equal 10.' 
           STOP 
EQUAL      KEY 'A1 equals 10.' 
           STOP

DO NOT put single quotes around the accumulator. The COMPARE command determines whether the compare action is numeric or string by checking the syntax of the statement. Single quotes around the accumulator indicate that it should be processed as a string. The COMPARE command does not recognize that the string refers to an accumulator.

For example, if A1 has a value of 3 and A2 has a value of 21, the following COMPARE statement compares the numeric values of the A1 and A2 and sets a condition code of LT:

COMPARE A1,A2

However, the single quotes in the following COMPARE statement indicate that A1 and A2 are to be compared as strings. As a result, the statement sets a condition code of NE because "A1" is not identical to "A2":

COMPARE 'A1','A2'