Objective C Loops by Example
While loop in Objective C
Example for while loop in Objective C is shown below.
int main(int argc, const char * argv[]) { @autoreleasepool { int a = 3; while(a > 2){ a = a - 1; NSLog(@"Greater than 2"); } } return 0; }
Do while loop in Objective C
Example for do while loop in Objective C is shown below.
int main(int argc, const char * argv[]) { @autoreleasepool { int a = 3; do{ a = a - 1; NSLog(@"Number is %d",a); }while(a>2); } return 0; }
For loop in Objective C
Example of for loop in Objective C is shown below.
int main(int argc, const char * argv[]) { @autoreleasepool { for(int i = 0; i<3; i++;){ NSLog(@"%d",i); } } return 0; }
Fast Enumeration(For in) in Objective C
Example for switch statement is shown below.
int main(int argc, const char * argv[]) { @autoreleasepool { NSArray *array = @[@"Eezy", @"Tutorials"]; for(id obj in array ){ NSLog(@"%@",obj); } } return 0; }