Search notes:

C: for

Exiting a for loop

A for loop is exited with the break keyword
#include <stdio.h>

int main() {

  int i;

  for (i=1; i<10; i++) {
    printf("i = %d\n", i);

    if (i == 5) {
    //
    // break exits the for loop, thus
    // only the numbers 1 through 5
    // are printed
    //
       break;
    }

  }
}
Github repository about-c, path: /for/break.c

See also

C language

Index