Pages: [1]   Go Down
Author Topic: syntax help...  (Read 380 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


or if you want to include 50 and 100:

  if( x >= 50 && x <= 100)
      doSomething();
« Last Edit: January 30, 2009, 01:37:00 pm by mem » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

any clues?

thanks so much
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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'
Logged

Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
int x = myWayOfCalculatingX();
if (50 <= x && x <= 100)
{
    /* ... */
}

« Last Edit: January 30, 2009, 03:23:15 pm by halley » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 40
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

maybe

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

?
Logged


Pages: [1]   Go Up
Jump to: