continue statement
In this chapter you will learn:
Use continue statement
continue
statement restarts the loop iteration.
The following code only prints out 6,7,8,9,10.
using System;/*from j a v a 2 s . c o m*/
class Program
{
static void Main(string[] args)
{
for (int i = 0; i <= 10; i++)
{
if (i <= 5)
{
continue;
}
Console.WriteLine(i);
}
}
}
The output:
continue within if statement
The following code combines the modular operator and continue statement to print out odd numbers only.
using System;/*from j a va2 s . c om*/
class Program
{
static void Main(string[] args)
{
for (int i = 0; i < 20; i++)
{
if (i % 2 == 0)
{
continue;
}
Console.WriteLine(i);
}
}
}
The output:
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Statements