May 17, 2024, 02:08:19 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


What if(1) means??

Started by Ficko, June 21, 2009, 11:02:27 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Ficko

June 21, 2009, 11:02:27 AM Last Edit: June 21, 2009, 11:07:15 AM by Ficko
I am studying the EB source lately and run into this in "CIntAssoc.eba -> SUB CIntToIntAssoc::NewAssoc(), pointer"

if(1)
....
endif

What the  purpose of that ?  :o

Ionic Wind Support Team

Usually when an IF statement is no longer needed I do that just to make sure it runs.  Just a leftover.

So in otherwords there used to be a condition there, that was removed when the code was rewritten, and I just got lazy ;)

Paul.
Ionic Wind Support Team

danbaron

June 23, 2009, 01:12:19 AM #2 Last Edit: June 23, 2009, 04:46:04 PM by danbaron
Hi Ficko.

Usually an IF statement looks like this:

IF (some equality or inequality) THEN (conditional statement)

or:

IF (some equality or inequality)
(conditional statements)
ENDIF

The equality or inequality (condition) evaluates to either TRUE or FALSE.

When the condition evaluates to TRUE, the conditional statement(s) is/are executed.

When the condition evaluates to FALSE, the conditional statement(s) is/are not executed.

My understanding is that in EB, TRUE means the number 1, and FALSE means the number 0.

Suppose you run the following statements in an EB console program.

PRINT FALSE
PRINT TRUE
PRINT (1 > 2)
PRINT (1 < 2)

The output will be:

0
1
0    (<-- because 1 is not greater than 2)
1    (<-- because 1 is less than 2)

The statement, IF(1), means IF(TRUE). Therefore, the conditional statements following IF(1), will always execute.

I guess, Paul needed the IF condition when he was testing the code.
And when he no longer needed it, instead of removing it, he performed the easier task, of just putting 1 as the condition of the IF.

So,

IF(1) THEN "something"

or

IF(1)
"something"
ENDIF

are identical to,

"something".

In effect the IF structure disappears (even though you can still see it).

(Apparently in EB, TRUE and FALSE, are pre-defined global constants.)

Dan.

------------------------------------------------------------------------------

I found some more stuff.

Suppose you run the following statements in an EB console program.

INT I =  9
INT J = -1
INT K = 0

IF I THEN PRINT I
IF J THEN PRINT J
IF K THEN PRINT K

The output will be

9
-1

I t seems like every non-zero INT, evaluates to TRUE.

But it doesn't work for DOUBLEs. The compiler will stop you.

Dan.
"You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump."  -  W.C. Fields