IonicWind Software

IWBasic => General Questions => Topic started by: Ficko on June 21, 2009, 11:02:27 AM

Title: What if(1) means??
Post by: Ficko on June 21, 2009, 11:02:27 AM
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
Title: Re: What if(1) means??
Post by: Ionic Wind Support Team on June 21, 2009, 01:30:40 PM
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.
Title: Re: What if(1) means??
Post by: danbaron on June 23, 2009, 01:12:19 AM
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.