- Hands-On Object:Oriented Programming with C#
- Raihan Taher
- 107字
- 2021-07-02 12:44:36
Continue
This is used to invoke the next iteration. The contextual keyword allows the developer to continue to the next step without executing any further code in the block.
Now, let's look at how we can use both of these contextual statements in our program:
var x = 0;
while(x<=10)
{
x++;
if(x == 2)continue;
Console.WriteLine(x);
if(x == 5) break;
Console.WriteLine("End of loop body");
}
Console.WriteLine($"End of loop, X : {x}");
The preceding code will skip execution of the body for the iteration value, 2, because of the continue statement. The loop will execute until the value of x is 5 because of the break statement.