Go Down

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

#### Shourtney

##### Jan 30, 2009, 07:29 pm
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 pmLast 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

#2
##### Jan 30, 2009, 07:42 pm
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

#3
##### Jan 30, 2009, 07:58 pm
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 pmLast 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

#5
##### Jan 30, 2009, 11:47 pm
maybe

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

?

Go Up

Please enter a valid email to subscribe