Operators for comparing
Help Contents
Logo and Logics
Operators for comparing
Operators for comparing
=, <, >, <=, >=, <>
When you ask Logo to compare two values, you say what action to use in order to compare.
There are 6 different ways to compare and there is an operator for each of them.
You can use the operators to find whether two values are equal (=) or not equal (<>), or whether a value is less (<), greater (>), less-or-equal (<=) or greater-or-equal (>=) to another value.
Values can be numbers, words and lists as shown below:
print 4 = 5 ; false
print 41 > 12 ; true
print "mouse < "mice ; false
print [h a t s] >= [c a t s] ; true
print [h a t s] <> [c a t s] ; true
Numbers are compared as numbers.
Words are compared alphabetically (in the way they are ordered in a dictionary) but capital letters always come first, thus A...Z section is before a...z.
Lists are compared in a more complex way. When you ask Logo to compare two lists, it start to compare their elements one by one.
When it reaches a pair of elements that are not equal, their relation defines the comparing of both lists.
If one list is shorter than another and all its elements are the same as those of another one, than the shorter list is smaller.
In all cases when you compare incomparable values, for example you ask whether 5 is equal to [1 2 3], Logo will return false as a result.
Otherwise it will compare the values and return either true or false.