RE: "if var!=-1 then" and "if not var=-1 then"
- Posted by CoJaBo <cojabo at suscom.net> Feb 25, 2004
- 512 views
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>