Take the 2-minute tour ×

Is it possible to write double inequalities in an if-statement?

ex: if (x <= y <= z) do stuff;

share|improve this question
Well, you can write them, they just don't mean what you probably expect. Your example would be parsed as if ((x <= y) <= z) do stuff;, and depending on whether x <= y would evaluate to if (1 <= z) or if (0 <= z). –  Daniel Fischer Dec 4 '12 at 1:04
add comment

1 Answer

Nope - Objective-C is a superset of the C language, and uses the same syntax as C for if statements. You'll have to split that up into two inequalities: if (x <= y && y <= z).

share|improve this answer
add comment

Your Answer


