Top  Previous  Next

It is often necessary to compare one value to another and make a decision based on the result. XPL0 uses the following symbols to make comparisons:


        =   Tests for equal values.

        #   Tests for not equal values.

        <   Tests if the first value is less than the second.

        >   Tests if the first value is greater than the second.

        >=  Tests if the first value is greater than or equal to the second.

        <=  Tests if the first value is less than or equal to the second.


Here are some expressions containing comparison operators:


        X = 3

        A < 0.91

        (X+1) >= Y


We have already seen an example of how XPL0 uses comparisons to make decisions. In the number guessing program, one of two statements were executed depending on a comparison:


        if Guess > Number then Text(0, "Too high")

        else Text(0, "Too low")


If the Guess was greater than the Number then it was "Too high"; otherwise it was "Too low".


XPL0 evaluates a comparison to true or false. These expressions evaluate to true:


        55 > 23

        (3*4) # (3+4)


These expressions evaluate to false:


        (2+2) = 5

        -33.3 > -4.5


WARNING: Since XPL0 treats all 16-bit integers as signed,


        $F000 > $A000   is true, but

        $F000 > $7000   is false.


Converting the hex to decimal makes the reason apparent:


        -4096 > -24576   is true, and

        -4096 >  28672   is false.