Different from break
, the continue
statement does not terminate the loop, instead it passes the control to the next iteration (Docs, 2015).
Using the previous example
for (int i = 0; i <= 10; i++)
{
if (i == 5)
{
continue;
}
Console.WriteLine(i);
}
The output will be:
0
1
2
3
4
6
7
8
9
10
where only the number 5
is skipped.
Live-code example
References
- Docs, M. (2015, July 20). continue (C# Reference). Retrieved from https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/continue