• Home
  •  Importance of Break and Continue Keywords

 Importance of Break and Continue Keywords

Agenda

Break Statement in C#

Syntax:

jump-statement; 

break;

Continue Statement in C#

Syntax:

jump-statement; 

break;


    for (int i = 0; i < 5; i++)
{
if (i == 2)
{
break;
}
Console.WriteLine(i);
}

for (int i = 0; i < 5; i++)
{
if (i == 2)
{
continue;
}

Console.WriteLine(i);
}

int i = 10;
while (i > 2)

{
Console.WriteLine(i);
i--;
if (i == 6)

{
break;
}
}

int i = 10;
while (i > 2)
{
Console.WriteLine(i);
i--;
if (i == 6)

{
continue;
}
}

int i = 10;
do
{
Console.WriteLine(i);
i--;
if (i == 6)

{
break;
}
} while (i > 2);

int i = 10;
do
{
if (i == 6)
{
i = i - 1;
continue;
}

Console.WriteLine(i);
i--;

} while (i > 2);
Console.ReadKey();

for (int outer = 0; outer < 5; outer++)
{
for (int inner = 0; inner < 5; inner++)
{
if (inner > outer)
{
break;
}

Console.Write($"{inner} ");
}
Console.WriteLine();
}