Logic Qbasics

Ok, time to get familiar with logical operators. Logical operators are extremely usefull when coding allmost anything. In matter affact, i cant even think coding with out these operators. With logical operators, you can compare variables easily and keep your code short and easy to read.

Let's take a example. My nick is E.K.Virtanen and my sex is male. Here we go Simplest possible example.

IF nick = E.K.Virtanen THEN PRINT "True"
IF sex = male THEN PRINT "True"

Ok, i bet you got that with out problems =) Let's go a bit further and take AND with us.

IF nick = E.K.Virtanen AND sex = male THEN PRINT "true"
IF nick = E.K.Virtanen AND sex = female THEN PRINT "false"
IF nick = K.E.Virtanen AND sex = male THEN PRINT "false"
IF nick = E.K.Virtanen AND sex = female THEN PRINT "false"

So with AND, both values have to be true to get result.

Next, let's see how OR works.

IF nick = E.K.Virtanen OR sex = male THEN PRINT "true"
IF nick = E.K.Virtanen OR sex = female THEN PRINT "true"
IF nick = K.E.Virtanen OR sex = male THEN PRINT "true"
IF nick = K.E.Virtanen OR sex = female THEN PRINT "false"

So, if both OR other clause is correct, then operator is true.

XOR is "wierdest" operator of these. It wants to be false =)

IF nick = E.K.Virtanen XOR sex = male THEN PRINT "false"
IF nick = K.E.Virtanen XOR sex = female THEN PRINT "false"
IF nick = E.K.Virtanen XOR sex = female THEN PRINT "true"
IF nick = K.E.Virtanen XOR sex = male THEN PRINT "true"

E.K.Virtanen; Public Domain

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.