Continue to next iteration of the loop - C Statement

C examples for Statement:continue

Introduction

The continue statement forces the next iteration of the loop to take place, skipping any code in between.

For the for loop, continue causes the increment statement in for loop and then the conditional test portions of the loop to execute.

For the while and do-while loops, program control passes to the conditional tests.

For example, the following program counts the number of spaces contained in the string entered by the user:

Demo Code

/* Count spaces */
#include <stdio.h>

int main(void)
{
   char s[80], *str;
   int space;//  w w  w  . ja va2s.  c  o  m

   printf("Enter a string: ");
   gets_s(s);
   str = s;

   for (space = 0; *str; str++) {
      if (*str != ' ') continue;
      space++;
   }
   printf("%d spaces\n", space);

   return 0;
}

Result


Related Tutorials