1. "if var!=-1 then" and "if not var=-1 then"

It there a differance between
if var!=-1 then
and
if not var=-1 then?

On a program I was working on here is what happened:

?st--displayed 5
if not st=-1 then
puts(1,"Hello!")--didn't run
--bunch of other stuff was here, didn't run
end if

Then I tried this to see what would happen:

st=-1
?st--displayed 5
if not st=-1 then
puts(1,"Hello!")--still didn't run
--bunch of other stuff was here,still didn't run
end if

Then I tried this:

?st--displayed 5
if st!=-1 then
puts(1,"Hello!")--Displayed "Hello!"
--bunch of other stuff was here, ran fine
end if

What is happening?!?!?

new topic     » topic index » view message » categorize

2. Re: "if var!=-1 then" and "if not var=-1 then"

Hello!

Looks like you need to check your operator precedence. I think what you are 
getting with 

not var = -1

is this ...

(not var) = -1

not this ...

not (var = -1)


So, it's testing the value of (not var) against the value of -1.

Of course, I'm not real sure ... but a thought.


------------------------
>From the Reference Manual:

 2.2.10 Precedence Chart 

The precedence of operators in expressions is as follows: 

        highest precedence:     function/type calls

                                unary-  unary+  not

                                *  /

                                +  -

                                &

                                <  >  <=  >=  =  !=

                                and  or  xor

        lowest precedence:      { , , , }

 

Thus 2+6*3 means 2+(6*3) rather than (2+6)*3. Operators on the same line above 
have equal precedence and are evaluated left to right. 
--------------------------

Travis W. Beaty
Osage, Iowa.




On Tuesday 24 February 2004 04:39 pm, CoJaBo wrote:
>
>
> It there a differance between
> if var!=-1 then
> and
> if not var=-1 then?
>
> On a program I was working on here is what happened:
>
> ?st--displayed 5
> if not st=-1 then
> puts(1,"Hello!")--didn't run
> --bunch of other stuff was here, didn't run
> end if
>
> Then I tried this to see what would happen:
>
> st=-1
> ?st--displayed 5
> if not st=-1 then
> puts(1,"Hello!")--still didn't run
> --bunch of other stuff was here,still didn't run
> end if
>
> Then I tried this:
>
> ?st--displayed 5
> if st!=-1 then
> puts(1,"Hello!")--Displayed "Hello!"
> --bunch of other stuff was here, ran fine
> end if
>
> What is happening?!?!?

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu