Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0085 continue statement

continue statement restarts the loop iteration. The following code only prints out 6,7,8,9,10. using System; class Program { static void Main(string[] args) { for (int i = 0; i <= 10; i++) { if (i <= 5) { continue; } Console.WriteLine(i); } } } The output: 6 7 8 9 10 The following code combines the modular operator and continue statement to print out odd numbers only. using System; class Program { static void Main(string[] args) { for (int i = 0; i < 20; i++) { if (i % 2 == 0) { continue; } Console.WriteLine(i); } } } The output: 1 3 5 7 9 11 13 15 17 19