if statements with more than once condition
Hi, I'm struggling a bit with figuring out how to add ranges as conditions in my if/else if statements. Rather than having conditions being above, below, or equal to X, I want to be able to find whether or not a statement fits a very specific condition.
How would you proceed with this problem? This is where I get stuck:
9 Replies
perfect place for
switch
Just FYI, variable names cannot start with a number
But if you wanted to use a chain of if-else, you certainly can
First check <= 10, then <= 20, then <=30
Then an else
I apologize, I just had to put up an example really quick
I actually didn't think of that. That's a pretty good idea
Thank you. I will look more into switch. I'll very likely use it at some point. Many thanks!
not only is switch clearer in these cases, the compiler (may) build it into a binary if tree, so its slightly faster.
I will write that down in my notes