Logical operators ( and, or, not )
Help Contents
Logo and Logics
Logical operators ( and, or, not )
Logical operators ( and, or, not )
Logical operators are those that deal with the logical values true and false, rather than those that are not illogical.
The operator and returns the word true only if its both arguments are true.
The operator or returns the word true when at least one of its two arguments is true.
The third operator not returns false if its only argument is true, otherwise it returns true.
A good place to use logical operators is when you want to form a complex condition in if or while.
if (5<:a) and (:a<10)
[ print :a "' is between 5 and 10' ]
if (5<=:a) or (:a>=10)
[ print :a "' is not between 5 and 10' ]
if not (5<:a)
[ print :a "' is less or equal to 5' ]
When using logical operators pay attention on the fact that Logo will not understand if you say it:
print :a > :b and :c
Well, it will understand this but most likely it will not be what you possibly meant.
So you must clearly say to Logo what exactly you mean:
print (:a > :b) and (:a > :c )
print (:a > :b) and :c
print :a > (:a and :c)