views:

2213

answers:

3

what is the proper way to do If statement with two variable in Xcode for Iphone

currently I have

if (minute >0) && (second == 0) {
minute = minute - 1;
second = 59;
}
+1  A: 

You'll need another set of parenthesis:

if ((minute >0) && (second == 0)) {
  minute = minute - 1;
  second = 59;
}
Dave DeLong
+1  A: 

The same was you would do it in any C/C++/Objective-C compiler, and most Algol derived languages, and extra set of parenthesis in order to turn to seperate boolean statements and an operator into a single compound statement:

if ((minute > 0) && (second == 0)) {
  minute = minute - 1;
  second = 59;
}
Louis Gerbarg
+1  A: 

Or you could also write:

if (minute > 0 && second == 0)

Which is what you'll start doing eventually anyway, and I think (subjective) is easier to read. Operator precedence insures this works...

Kendall Helmstetter Gelner