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

> -----Original Message-----
> From: CoJaBo [mailto:cojabo at suscom.net]
> Subject: "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

Try this instead...

 if not (st=-1) then
   puts(1,"Hello!")
 end if

What is happening with your code is equivalent to this ...

 if (not st)=-1 then
   puts(1,"Hello!")
 end if

Thus if st is 5, then (not st) is 0, thus it is like saying 'if 0 = -1 then
..."

--
Derek

new topic     » topic index » view message » categorize

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

Thanks, but can anyone explain why, with the same code, this only 
started happening now?

Travis Beaty wrote:
> 
> 
> 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

3. RE: "if var!=-1 then" and "if not var=-1 then"

I've been using this in the same program for a long time and this only 
just started happenning, nothing I've changed could have affect that 
part of the program. Does anyone know why this started happenning only 
about an hour ago?

CoJaBo wrote:
> 
> 
> Thanks, but can anyone explain why, with the same code, this only 
> started happening now?
> 
> Travis Beaty wrote:
> > 
> > 
> > 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?!?!?
> > 
> > 
<snip>

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

4. RE: "if var!=-1 then" and "if not var=-1 then"

> -----Original Message-----
> From: CoJaBo [mailto:cojabo at suscom.net]
> Subject: RE: "if var!=-1 then" and "if not var=-1 then"
>
>
>
> I've been using this in the same program for a long time and
> this only
> just started happenning, nothing I've changed could have affect that
> part of the program. Does anyone know why this started
> happenning only
> about an hour ago?

Either its always being doing this but you only just noticed, you have
actually changed the code without realizing it, or you have ghosts in your
machine. Euphoria, and programs in general, do not change themselves. But
you already knew that.

--
Derek

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

Search



Quick Links

User menu

Not signed in.

Misc Menu