C programming continue statement
Continue statement in programming for changing the flow of the loop. In this chapter you will learn how to change the flow of different loops in C programming using the continue statement.Some of the statements inside the loop need to be avoided. The current statement is used in this case.
Continue statement
The current statement looses some statements in the loop. The statement used for decision-making, such as if ... else statement is used in the statement.
Continue statement syntax
continue;
Continue Statement Flowchart
Flowchart of continue statement
How does the release statement work?
Work of continuing statement in C programming
Example 1: continue statement
#include <stdio.h>
#include <conio.h>
int main ()
{
int i = 1; // local variables have been initialized.
clrscr ();
for (i = 1; i <= 10; i ++) // 1 to 10 loop will run
{
If the value of i (i == 7) // i equals 7, the loop will be running
{
continue;
}
printf ("% d \ n", i);
} // for the end of the loop
getch ();
}
Output
1
2
3
4
5
6
8
9
10
Example: Continue statement
// Program to add maximum number 5
// Keeping the sum of the user's positive numbers started to be evaluated.
# include <stdio.h>
int main ()
{
int i;
double number, sum = 0.0;
for (i = 1; i <= 5; ++ i)
{
printf ("Enter a number% d:", i);
scanf ("% lf", & number);
// Enter the negative number of the user just continue to execute the statement
// and skip this statement and check the next test expression.
if (number <0.0)
{
continue;
}
sum + = number; // sum = sum + number;
}
printf ("Sum =% .2lf", sum);
return 0;
}
Output
Enter a number1: 5.6
Enter a number2: -2.5
Enter a number3: 10
Enter a number4: 15.5
Enter a number5: -2.2
Sum = 31.10
Entering user positive numbers in the above program sum + = number; Under the statement, the sum is being calculated.
But when the user enters a negative number then the current statement is executed and excludes the negative number from the count.
0 Comments