In this tutorial you will learn about the C Continue Statement and its application with practical example.
C Continue Statement
It will give you a way to skip over the current iteration of any loop. When a continuous statement is encountered in a loop, the rest of the statements in the loop body for the current iteration ends and returns the program execution to the very first statement in the loop body. It does not terminate the loop rather continues with the next iteration.
Continue Statement Flow Diagram
Continue Statement Syntax
Below is the general syntax of the continue statement in c programming:
Syntax:-
1 |
continue; |
Continue Statement Example
Below is a simple example to demonstrate the use of the continue statement in c programming:
Example:-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include <stdio.h> int main() { int ctr = 0; printf("W3Adda - C Continue Statement"); while(ctr < 10){ ctr = ctr + 1; if(ctr == 5){ printf("\n5 is skipped"); continue; } printf("\nNumber is %d",ctr); } printf("\nOut of while loop"); return 0; } |
When we run the above C program, we will see the following output –
Output:-
As you can see when ctr == 5, the continue statement is executed which causes the current iteration to end, and the control moves on to the next iteration.