Qbasicnews.com

Full Version: logical operators Q
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
Not 100% sure if conversions are correct.
Are they?

Code:
AND:
IF a AND b THEN
c
END IF
------
IF "a" THEN
IF "b" THEN
c
END IF
END IF

OR:
IF a OR b THEN
c
END IF
------
IF a THEN
c
ELSE
IF b THEN
c
END IF
END IF

XOR:
IF a XOR b THEN
c
END IF
------
IF a THEN
IF NOT b THEN
c
END IF
ELSE
IF b THEN
c
END IF

EQV:
IF a EQV b THEN
c
END IF
------
IF a THEN
IF b THEN
c
END IF
ELSE
IF NOT b THEN
c
END IF

IMP:
IF a IMP b THEN
c
END IF
------
IF a THEN
c
END IF
The transformations upto XOR look good. But I am not sure about the last two.
this is wrong:

Code:
OR:
IF a OR b THEN
c
END IF
------
IF a THEN
c
ELSE
IF b THEN
c
END IF
END IF

It should be:

Code:
IF a THEN c
IF b THEN c
Quote:this is wrong:

Code:
OR:
IF a OR b THEN
c
END IF
------
IF a THEN
c
ELSE
IF b THEN
c
END IF
END IF

It should be:

Code:
IF a THEN c
IF b THEN c

No, what he put is still correct, in that it will execute c when and only when using an OR would. It just is longer than it needs to be.
Nevermind ... too much pot Big Grin

(in fact, somehow, I was thinking in prolog Tongue)
Actually your code would execute c twice.....
Quote:Actually your code would execute c twice.....

No, the ELSE clause cannot execute if the IF part does.
That's right........

................
Quote:
Agamemnus Wrote:Actually your code would execute c twice.....

No, the ELSE clause cannot execute if the IF part does.

He was refering to Na_th_an's code.... :-?
Quote:
PlayGGY Wrote:
Agamemnus Wrote:Actually your code would execute c twice.....

No, the ELSE clause cannot execute if the IF part does.

He was refering to Na_th_an's code.... :-?

Woops. And he is right.
Pages: 1 2 3