-
Simple question
Hello all those who read this post,
Ive decided to learn some C and have run into a problem.
I just want to know if the condition in an if statement can be something like the following:
if (10< i <15) {
...
so far ive only been able to get it to work when it would have only one inequality in it, but is it possible to have 2? and if not, is there some function or something that i can use to make it possible (i need it for a simple program im making right now)?
Thanks,
PPeter
-
You would write that as
Code:
if ((i >10) && (i < 15))
DoSomethingWonderful();
The more explicit you are the better your code works.
-
do this:
Code:
if(10 < i && i < 15)
The && is the logical and opperator, which yeilds true when both opperands passed to it are true. In this case it's asserting that 10 < i and i < 15. It has a lower precidence than most opperators.
II is the or operator and it is also common for connecting multi-part criteria like this.
-
Wow, that was much faster than i thought it would take.
Thanks CommonTater, and King Mir, this will really help.