A for Loop with No Parameters - C Statement

C examples for Statement:for

Introduction

You have no obligation to put any parameters in the for loop statement.

The minimal for loop looks like this:

for( ;; ){
  /* statements */
}

Because the condition for continuing the loop is absent, the loop will continue indefinitely.

Demo Code

#include <stdio.h> 
#include <ctype.h> 

int main(void) { 
    /*from   w w w.j a v a  2s .  c o  m*/
    char answer = 0;
    for( ;; ){
      printf("Do you want  to enter some more(y/n): ");
      scanf("%c", &answer);
      if(tolower(answer) == 'n')
        break;                               // Go to statement after the loop
    }

    return 0; 
}

Result


Related Tutorials