Use break in for loop to exit : For Break « Language Basics « C / ANSI-C






Use break in for loop to exit

  
#include <stdio.h>

int main(void)
{
  int i;

  for(i = 1; i < 100; i++) {
    printf("%d ", i);
    if(i == 10) 
        break; /* exit the for loop */
  }

  return 0;
}

           
       








Related examples in the same category

1.indefinite loop and break
2.Break a infinite loop
3.Use break to terminate a for loop
4.Nested for loop and break