Continue Statement in C++

Continue Statement in C++
Techiio-author
Written by Sagar RabidasFebruary 8, 2022
7 min read
C++
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

In this blog, we will discuss Continue Statement in C++

Continue Statement in C++

The continue statement is a loop control statement used inside the loop. To implement the continue statement, C++ uses the continue keyword which transfers the flow of the program at the beginning of the loop and skips the current statement when it is encountered.

Syntax:

Continue keyword is used. The syntax for the continue statement in C++ is as follows:

continue;

How does Continue Statement Work in C++?

Primarily based on the loop condition the statements inside the loop are completed. If the given condition is proper it maintains the generation of the loop. If the given situation is fake, the loop will be terminated. If the retain statement is referred to in the loop, it skips the cutting-edge declaration and transfers manipulate to execute the following iteration of the loop. To apprehend how precisely the retain declaration works in c++, let’s discuss some examples for better expertise.

Example #1 – Usage of Continue Statement in For Loop

In the following C++ program, we will see how to use of continue statement in a For loop. For this, the user can provide the number, and then the result will be displayed on the screen:

Code:

#include<iostream>
using namespace std;
int main()
{
int i, n;
cout << "Enter a number";
cin >> n
for(i = 0; i <=n; i++)
{
if(i == 2)
{
continue;
}
cout << "List of numbers";
cout << i;
}
return 0;
}

Output:

blogpost

  • Explanation of the above Program: Inside the above software, to show the implementation of the maintain statement, we've got used for loop technique. This system is written to print the list of numbers distinctive with the aid of the person. Right here we have initialized two variables n to store the value and me for the generation. This system first asks the user to enter the variety after which keep the number into n. In for loop, we've got initiated I to 0 and cited a circumstance that assessments that I should be much less than or identical to n. In the loop, we've got noted the continued statement to bypass number 2. Once I emerge as 2, it skips that cost and keeps the loop. If the variety isn't 2, then the declaration out of doors the if will be achieved and prints the number one by one.

Example #2 – Usage of Continue Statement in While Loop

In the following C++ program, we will see how to use of continue statement in a While loop then the result will be displayed on the screen:

Code:

#include<iostream>
using namespace std;
int main()
{
int i, n;
cout << "Enter a number";
cin >> n
while(i <= n)
{
if(i == 2)
{
i++;
continue;
}
cout << "List of numbers";
cout << i;
i++;
}
return 0;
}

Output:

blogpost

  • Explanation of the above Program: In the above program, to reveal the implementation of the preserve announcement, we've got used the whilst loop method. The program is written to print the listing of numbers detailed with the aid of the person. Right here we have initialized two variables n to keep the value and me for the new release. This system first asks the person to go into the quantity and then save the number into n. Even as a loop, we've initiated I to 0 and mentioned a condition that exams that I need to be less than or same to n. Inside the loop, we've got noted the retain assertion to pass wide variety 2. After I turn out to be 2, it skips that price and keeps the loop. If the number is not 2, then the declaration outside the if can be achieved and prints the number one via one.

Example #3 – Usage of Continue Statement in Do While Loop

In the following C++ program, we will see how to use of continue statement in a Do While loop then the result will be displayed on the screen.

Code:

#include<iostream>
using namespace std;
int main()
{
int i, n;
cout << "Enter a number";
cin >> n
do
{
if(i == 2)
{
i++;
continue;
}
cout << "List of numbers";
cout << i;
i++;
}while(i <= n);
return 0;
}

C
C++
Continue Statement
0 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 0 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance