Advertisement



< Prev
Next >



C# Continue Statement





In C#, when the continue statement is encountered in an executing loop of a program, it skips executing the rest of statements in the loop for that particular iteration and the program continues with the next iteration and condition checking in the loop.




Note :


The continue statement must be inside a loop, otherwise a compile error is issued by compiler at the time of compilation of the program..





Advertisement




Continue statement example


//C# Continue statement example

using System;

class ContinueEx
{
public static void Main()
{
	//The for loop to print digits from 5 to 9
	for(int i=5;i<10;i++)
	{	
		//If i==7 the associated continue statement is executed
		if(i==7)
			continue;	
		
		//Printin the value of i, if i is not equal to 7
		Console.WriteLine("i = "+i);
	}
	Console.WriteLine("Out of the loop");
}
}


Output


i = 5
i = 6
i = 8
i = 9
Out of the loop

As you may see in the output of the program, when the continue statement was encountered within an executing for loop, it skipped executing the Console.WriteLine() statement in the loop for that particular iteration i.e. when i is equal to 7. The program continued normally with the next iteration(i is equal to 8) and its condition checking.



Please share this article -





< Prev
Next >
< C# Break Statement
C# Switch Statement >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement