C examples for Statement:break
The break statement works the same way within the body of a loop-any kind of loop.
For instance:
#include <stdio.h> #include <stdlib.h> #include <ctype.h> int main(void) { char answer = 0; for (;; )/*from w w w . ja v a 2 s. c om*/ { printf("Do you want to enter some more(y/n): "); scanf("%c", &answer); if (tolower(answer) == 'n') break; // Go to statement after the loop } return 0; }
Here you have a loop that will potentially execute indefinitely until a n letter input.