break statement terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.
#import <Foundation/Foundation.h> int main () { /* local variable definition */ int a = 10; /* while loop execution */ while( a < 20 ) { NSLog(@"value of a: %d\n", a); a++; if( a > 15) { /* terminate the loop using break statement */ break; } } return 0; }
The code above generates the following result.
#import <Foundation/Foundation.h> int main () { int i; for (i = 0; i < 5; i++) { NSLog (@"The value of i = %i", i); if (i == 2) { break; } } return 0; }
The code above generates the following result.