testing for multiple conditions (alot of conditions)

hello all, I was wondering what is the best way to test for multiple conditions, if or switch case.

I need to test for 42 separate conditions. each condition will do a separate statement. there will never be a combination of conditions. the condition will be 0 - 41. I don't think if statement will be the best way, but maybe. I hope I explained as simple as needed. - Thanks

What kind of conditions?

Is it something you could do with a switch-case?

Chains of if/else if/else are very common in programming, and it's quite possible that that's the Right Way.

conditions are simple - var=0 and so on. this variable is coming from visual studio. it will pass (var) to sketch and depending which value is passed it will execute a command to one of three servos.

If they're just numbers use switch case

the condition will be 0 - 41.

Do you mean that literally. ie that there will be a variable with a value of 0 to 41 and based on its value you need to execute one of 42 functions ?

yes

Use a function pointer table.

gadgfreak:
it will pass (var) to sketch and depending which value is passed it will execute a command to one of three servos.

I have a feeling that if you were to tell us what you want to achieve somebody will suggest a much simpler solution than working through 42 IF or CASE statements.

...R

AWOL's array of function pointers sounds very attractive; shortest code that you can get :wink:

sterretje:
AWOL's array of function pointers sounds very attractive; shortest code that you can get :wink:

That was what I had in mind when I asked what the OP wanted to do.

...and "alot" is not a word.
"Allot" is, but isn't what you mean.
"A lot" is two words, and is what you mean.

sorry guys, after thinking about it more, the biggest chunk was in a function that had 30 options. Needed to take an input from 60 to 90 and multiply it out by 9 to end up with 0 - 270. Had a loss of brain function there for a bit. I reduced it down to 1 statement to do this.

Sorry that "alot" wasn't captured by spell check.

Thanks for all the quick responses.