I am relatively new to programming and came across an if statement that I believe to be a bit verbose. I have tested my code and it appears to work without any issues, but I am wanting to know if there is a more efficient means or better shorthand of checking "day".
if (day == 1 || day == 21 || day == 31) {
NSLog(@"Today is the %lust day of the month", day);
} else if (day == 2 || day == 22) {
NSLog(@"Today is the %lund day of the month", day);
} else if (day == 3 || day == 23) {
NSLog(@"Today is the %lurd day of the month", day);
} else {
NSLog(@"Today is the %luth day of the month", day);
}
Aucun commentaire:
Enregistrer un commentaire