Infinite for loop with break : For « Language Basics « C / ANSI-C






Infinite for loop with break

  
  
#include <stdio.h>

int main(void) {
    char ch;
    
    for( ; ; ) { /* infinite for loop */
        printf("Load, Save, Edit, Quit?\n");
        do {
            printf ("Enter your selection: ");
            ch = getchar();
        } while(ch!='L' && ch!='S' && ch!='E' && ch!='Q');

        if(ch == 'Q') 
            break;

    }

  return 0;
}
           
       








Related examples in the same category

1.For statement: backwards
2.For : no first part
3.For: no init and loop backwards
4.Nested forNested for
5.For loop: List ten integersFor loop: List ten integers
6.For loop: Draw a boxFor loop: Draw a box
7.Use int as the while loop controller
8.Simplest for loop: user control the loop
9.Use for loop as the user selection's controller
10.Demonstrate multiple loop control variablesDemonstrate multiple loop control variables
11.Use function as for loop control variable
12.For loop without first part
13.For loop without the third part
14.See the for loop terminating condition
15.For loop condition: loop will not execute
16.For loop: bigger increase
17.Prime number tester
18.nested for Demo
19.Use integer as the for loop controller
20.Set the init value for a for loop
21.More calculation in the for statement
22.Simplest for loop
23.Reverse order of for loop
24.Two condition for ending a for loop
25.Three level nested for loop
26.A simple for loopA simple for loop
27.More complex for loop: more statements
28.For loop with init value, stop condition and incr
29.Use char as int in a for loop
30.Nested for loop demo