Breaking out of a for loop : Break « Statement « C Tutorial






#include <stdio.h>
 
int main()
{
    char ch;
 
    puts("Start typing");
    puts("Press ~ then Enter to stop");
 
    for(;;)
    {
        ch=getchar();
        if(ch=='~')
        {
            break;
        }
    }
    printf("Thanks!\n");
    return(0);
}
Start typing
      Press ~ then Enter to stop
      
      12312
      1
      231
      
      12
      12
      3~
      Thanks!








6.9.Break
6.9.1.The break statement
6.9.2.Breaking out of a for loop