c++ continue statement

continue statement

The break statement solves the problem of ending the loop early, but sometimes we just want to end the current round of the loop, but still let the loop continue, then use the continue statement to solve this problem. The continue statement will not be directly transferred to the back of the entire loop, but will jump back to the conditional judgment, so that the remaining code of the current loop will not be executed, and the new loop can still continue.

continue statement

#include <iostream>
using namespace std;

//continue 语句

int main()
{
    
    
	for (int i = 0 ;i<10;i++)
	{
    
    
		if ( i % 2 ==0 )
		{
    
    
			continue;
		}
		cout << i <<endl;
	}
	return 0;
}

operation result:

In the example recirculation, every time i is divisible by 2 and the remaining 0 is encountered, that is, i is even, use continue to skip the subsequent code of this cycle and enter the next cycle, so that only odd numbers will be printed out .

If this article is helpful to you, please like and support it~

Guess you like

Origin blog.csdn.net/m0_62870588/article/details/123690338