JuniorFlip
JuniorFlip

Reputation: 417

multiple instance if statement in xcode (iphone)

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;
}

Upvotes: 2

Views: 23662

Answers (3)

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...

Upvotes: 1

Louis Gerbarg
Louis Gerbarg

Reputation: 43462

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;
}

Upvotes: 6

Dave DeLong
Dave DeLong

Reputation: 243166

You'll need another set of parenthesis:

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

Upvotes: 1

Related Questions