Jan
Jan

Reputation: 663

Check if NSNumber is between two values

What is the correct if statement to check if a NSNumber is between two values? For example between 33 and 66?

if ([myNumber intValue] < 33) {

}

Upvotes: 0

Views: 380

Answers (1)

Glorfindel
Glorfindel

Reputation: 22641

Objective C is an extension of C, so you can combine two comparisons with &&:

if ([myNumber intValue] > 33 && [myNumber intValue] < 66) {

Or modern style:

if (myNumber.intValue > 33 && myNumber.intValue < 66) {

Upvotes: 3

Related Questions