Logic Basic tutorial for beginners
Logical operators

Logical operators And and Or can be used in the command line of If or While to perform logical operations between expressions. The operator And performs a logical operation between expressions so that it returns a true result if all expressions are true at the same time, at least one of the expressions is false, it returns false. The operator Or performs a logical operation between expressions so that at least one of the expressions is true, it returns a true result, and returns false only if all expressions are false. You can perform logical operations with various expressions on the same line and also put more than one operator on the same line.

Below, examples of logical operators:

Variable X Integer, Y Integer

X = 1
Y = 1

If X = 1 And Y = 1 'Returns True
Write "True"
Else
Write "False"
EndIf

If X = 1 And Y = 2 'Returns False
Write "True"
Else
Write "False"
EndIf

If X = 1 Or Y = 2 'Returns True
Write "True"
Else
Write "False"
EndIf

If X = 2 Or Y = 2 'Returns False
Write "True"
Else
Write "False"
EndIf

Back to index      Next topic