break
Anweisung
Die break
-Anweisung bewirkt einen sofortigen Sprung zum Ende der aktuellen for
-, while
- oder do-while
-Schleife oder der aktuellen switch
-Struktur.
number is 0. number is 1. number is 2. number is 3. number is 4. number is 5. number is 6. number is 7. number is 8. Finished.
#include <stdio.h> int main(){ int i = 0; switch(i){ case 0: printf("number is %d.\n", i); break; default: printf("Something went wrong.\n", i); } for(i = 1; i < 10; ++i){ printf("number is %d.\n", i); if(i == 2){break;} } ++i; while(i < 10){ printf("number is %d.\n", i); if(i == 5){break;} ++i; } ++i; do { printf("number is %d.\n", i); if(i == 8){break;} ++i; } while(i < 10); printf("Finished.\n"); return 0; }