Go Down

Topic: syntax help... (Read 469 times) previous topic - next topic

Shourtney

im trying to figure out how to set a value to be between two numbers and I cant resolve the syntax...

for instance x = 50 to 100

if x = anything between those two numbers, do y...

thanks!

mem

#1
Jan 30, 2009, 07:36 pm Last Edit: Jan 30, 2009, 07:37 pm by mem Reason: 1
 if( x > 50 && x < 100)
     doSomething();


or if you want to include 50 and 100:

 if( x >= 50 && x <= 100)
     doSomething();

Shourtney

the problem that I am having is that I am already having to call out the value of x...

any clues?

thanks so much

mem

Quote
the problem that I am having is that I am already having to call out the value of x...


I don't understand, can you explain what you mean by 'call out the value of x'

halley

#4
Jan 30, 2009, 09:22 pm Last Edit: Jan 30, 2009, 09:23 pm by halley Reason: 1
If you mean that your particular x is a function call, and you don't want to call it twice, then just get a real variable first.

Code: [Select]
int x = myWayOfCalculatingX();
if (50 <= x && x <= 100)
{
   /* ... */
}



combatdave

maybe

Code: [Select]

for (int x=50;x<=100; x++)
{
 myFunction_y(x);
}


?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy