int j;
for (j = 0; j <= 10; j++)
{
if (j == 7)
{
Console.WriteLine("Found 7");
continue;
Console.WriteLine(j + "\n");
like this
int j;
for (j = 0; j <= 10; j++)
{
if (j == 7)
{
Console.WriteLine("Found 7");
continue;
it only prints 7
Thanks
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

VulpesRank #55 · 29.2K reputationPosted Nov 1, 2013, 1:09 PM EDT
In your snippet. this line:
Console.WriteLine(j + "\n");
is unreachable because it is preceded by the continue statement which will always jump over it to the end of the for statement.
We can correct that and print all the numbers as follows:
using System;
class Program
{
static void Main()
{
int j;
for (j = 1; j <= 10; j++)
{
if (j == 7)
{
Console.WriteLine("Found 7" + "\n");
continue;
}
Console.WriteLine(j + "\n");
}
Console.ReadKey();
}
}
The offending line is now outside the if statement and so will print all the numbers except 7.
Tito Onowu26 reputationPosted Nov 1, 2013, 1:44 PM EDT