Continue Statement C [ Full Information With Examples ]
Continue Statement C
Continue Statement is a loop control statement that we use in C language when we want to run the program from next iteration by skipping a particular line or code when a particular condition becomes true.
Suppose you are playing a game and in order to cross a level in that game you need some particular point within a particular time.
If you have achieved that point before time, then the game starts at the next level.
In the same way, when we have some special condition in our program, we want to start the program with the next iteration, then we have to use the continue statement.
The continue statement is slightly opposite to the break statement. It does not take the control of the program out of the entire loop, but takes the control of the program to the beginning of that loop and runs the loop with the next iteration.
The continue statement is mostly used inside a loop statement with an if condition.
Syntax of Continue Statement In C
// loop statements
continue;
// some lines of the code which is to be skipped
Example: Continue Statement inside for loop
#include <stdio.h>
int main ()
{
for (int j = 0; j <= 10; j ++)
{
if (j == 5)
{
/* The continue statement is encountered when
the value of j is equal to 5.
*/
continue;
}
/* The printf () statement will not run when j == 5 because
continue statement has run before and
The control has reached the beginning of the loop.
*/
printf ("% d \n", j);
}
return 0;
}
Output -:
0
1
2
3
4
6
7
8
9
10
Look at the output of the program, it does not print 5 because the continue statement is run when the j == 5 condition is true so that the control of the program returns to the loop again and the program starts with the next iteration.
Example: Use of Continue in While loop
In this example, we will use the continue statement inside While Loop. When we use the continue statement inside While Loop, then we have to use the counter statement (increment ++ and decrement – operator) before the continue statement.
#include <stdio.h>
void main ()
{
int counter = 10;
while (counter>=0)
{
if (counter == 7)
{
counter--;
continue;
}
printf ("%d", counter);
counter--;
}
}
Output -:
10 9 8 6 5 4 3 2 1 0
Look at the output of this program, the output of the program did not print 7 because as soon as the counter == 7 condition was done, the Continue statement went and the control of the program went to the beginning of the while loop and the program started running from next.
Example: Use of Continue in Do While loop
#include <stdio.h>
int main ()
{
int j = 0;
do
{
if (j == 7)
{
j++;
continue;
}
printf ("%d", j);
j++;
} while (j<10);
return 0;
}
Output -:
0 1 2 3 4 5 6 8 9
Read More -:
- Control Statements in C
- If else Statement in C
- Loop in C
- For Loop in C
- While and Do while Loop in C
- Switch Statement in C
- Goto Statement in C
- Conditional Operator in C
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
Friends, I hope that after reading this post today, you have learned what is Continue Statement In C Language. And how to use Continue Statement in C language.
Friends, I hope you have found the answer of your question and you will not have to search about the Continue statement in C language.
However, if you want any information related to this post or related to programming language, computer science, then comment below I will clear your all doubts.
If you want a complete tutorial of C language, then see here C Language Tutorial. Here you will get all the topics of C Programming Tutorial step by step.
Friends, if you liked this post, then definitely share this post with your friends so that they can get information about the Continue statement in C Language.
To get the information related to Programming Language, Coding, C, C ++, subscribe to our website newsletter. So that you will get information about our upcoming new posts soon.