Friday, July 29, 2016

C Basics - The continue Statement in C

In some programming situations we want to take the control to the beginning of the loop, bypassing the statements inside the loop, which have not yet been executed. The keyword continue allows us to do this.

The syntax for a continue statement is,


When continue is encountered inside any loop, control automatically passes to the beginning of the loop. For the for loop, continue statement causes the conditional test and increment portions of the loop to execute. For the while and do...while loops, continue statement causes the program control to pass to the conditional tests.

#include <stdio.h>
int main () {

   int i = 1;

   do {
      if( i == 5) {
      printf("value of i is: %d\n", i);
   } while( i < 10 );
   return 0;

Output of above program,

value of i is: 1
value of i is: 2
value of i is: 3
value of i is: 4
value of i is: 6
value of i is: 7
value of i is: 8
value of i is: 9

Related topics:
Loops in C   |   The for Loop in C   |   The while Loop in C   |   The do-while Loop in C   |   Nested Loop in C   |   Infinite Loop in C   |   Loop Control Statements in C   |   The break Statement in C   |   The goto Statement in C   |   The return Statement in C

List of topics: C Programming

No comments:

Post a Comment