conditional statements

Discuss PocketC for Palm OS (including Desktop Edition)

Postby Velvis on Mon Apr 23, 2001 4:36 pm

I have some code that I would like to run if the following conditions are met:
if (HighValue!=LowValue or HighValue!=-MAX_VAL or HighValue!=0){run code}

I was assuing this means if any of these are true the code will not run, but the loop runs even when a condition is met (ie HighValue==-MAX_VAL which means the code shouldnt run.
The statement I used is the following:
if (HighValue!=LowValue || HighValue!=-MAX_VAL || HighValue!=0)

Maybe I am confused or have been looking at it too long, but I'm stuck and figured a fresh pair of eyes could find the problem.
Posts: 226
Joined: Mon Dec 11, 2000 2:32 am

Postby jstadolnik on Mon Apr 23, 2001 5:45 pm

It looks like you want to use && (AND) rather than || (OR).

Posts: 1741
Joined: Wed Dec 06, 2000 3:34 am
Location: USA

Postby Velvis on Tue Apr 24, 2001 12:30 pm

Thanks Joe, worked great. At some point I will try an figure out why my way doesnt work and yours does....
Posts: 226
Joined: Mon Dec 11, 2000 2:32 am

Postby samps on Tue Apr 24, 2001 8:49 pm

Even though your formula is mathematically correct, it won't work due to the way the PocketC (and other C's) work.
What happens is, that the program starts evaluating from either right or left, and as soon as 1 of the OR-statements evalute to true, the task is being run.
The problem is that in order to run at the right time, all the evaluations would have to turn out true, and that can't happen as your sentence is contructed.


Edited by - samps on 04/24/2001 15:53:00
Ubuntu user #82
Posts: 143
Joined: Tue Feb 20, 2001 12:33 am
Location: Australia

Return to PocketC for Palm OS

Who is online

Users browsing this forum: No registered users and 4 guests