1 if
Mrhiggieismean = NO; if (Mrhiggieismean) { NSLog (@ "confirmed:he is super mean");}
2 if Else
BOOL Mrhiggieismean = [Mrhiggie Areyoumean]; if (Mrhiggieismean) { NSLog (@ "confirmed:he is super mean");} Else { NSLog (@ "No, actually he ' s reallynice");}
3 If-else If-else
NSNumber *meannessscale =[Mrhiggie Meannessscale];if([Meannessscale Intvalue] <4) {NSLog (@"Mr. Higgie is on the nice side");} Else if([Meannessscale Intvalue] <8) {NSLog (@"Mr. Higgie is sorta nice and not really");} Else{NSLog (@"Mr. Higgie is definitely mean");}
4 Equal Strings
Passed to isequaltostring: compares two nsstring, returns True if same, and returns false instead.
Can be used in the conditional judgment of if:
if ([myString isequaltostring:otherstring]) { NSLog (@ "Hello from inside the if! " );}
5 Switch case
Nsinteger Day =GetDayOfWeek ();Switch(day) { Case 1: {NSLog (@"Monday"); Break; } Case 2: {NSLog (@"Tuesday"); Break; } /*snip Wednesday through Saturday*/ Case 7: {NSLog (@"Sunday"); Break; }}
6 Switch on Enums
The flash used by switch is used in conjunction with enumerations.
typedef ns_enum (Nsinteger, DayOfWeek) { 1, 2, 3 , 4 , 5 , 6 , 7 };
Objective-c level-3