IF (K=69)*(R>1)THEN {Do Something ...}
What you are doing is really a logic test.
For example, using an IF statement, if I do:Code: [Select]IF (K=69)*(R>1)THEN {Do Something ...}
What I am saying is K=69 returns a 0 or -1, AND R>1 returns a 0 or -1. The * does not mean multiply, it acts as the logical AND. The division / is the logical OR.
You still need to do an IF statement if you want to perform something if the condition is TRUE or FALSE (See code below):Code: QB64: [Select]
K = 68 R = 0 K = 69 R = 2 K = 69 R = 1
The result of the first IF statement returns a 0 for BOTH conditions, where the second IF returns a -1 for BOTH, and the third IF returns a 0 and -1 respectively.
This was used in old BASIC code (can still be done today) when doing graphics, to test if a cursor was at the left, right, top or bottom of the screen, or to test if you pressed a specific key on the keyboard while at a specific location. Or used to detect collisions in games by comparing two location values.
Why isn't this line throwing a Div by 0 Error?Code: QB64: [Select]
It will if you use "\" instead of "/".
310 IF S=0 THEN 280
320 IF K=81 THEN 520
330 IF (K=69)*(R>1)THEN 390
340 IF (K=a3)*(C>3)THEN 410
350 IF (K=68)*(C<31)THEN 430
360 IF (K=88)* (R<22)THEN 453
Code: QB64: [Select]
K = 69 R = 1 'Compare to this Print "Comparing:" K = 69 R = 1
It's not printing "One is true" because one is true but because this "-INF D " <> 0.
You're seeing division by zero, which folks chose to make results be NaN (Not a Number), rather than "ERROR: DIVISION BY ZERO".
In QBASIC, False is 0, *anything else* is true. Since NAN isn't 0, it's TRUE.
It's the results the user base chose somewhere around version 0.2 when asked what they preferred to happen: Toss Errors and stop program execution, or make the result NAN.
Folks chose the NAN behavior, so now that's what we have.
As odd as it is, it was intentionally made that way by the vote of the majority of the user base. Just like REM is a command, but ’ is a just a remark...
Try
:
IF X THEN REM
vs
IF X THEN '
See the difference in behavior? Folks CHOOSE that on purpose!
I am not complaining of the vote to avoid the Div by 0 error, though I think I would have voted different, I am saying the division trick or tip won't work as an Alternate OR test as it may once have done in another BASIC PL.