Home
>
Google > What statements can come with “continue” statement in C#
What statements can come with “continue” statement in C#
The continue statement is used to pass the control to the next iteration of the loop it is in. So, it can only be used with loops.
for
1
2
3
4
5
6
7
8
| for (int I = 0; I < 10; I++)
{
if (I % 2 == 0)
{
continue;
}
Console.WriteLine(I);
} |
foreach
1
2
3
4
5
6
7
8
9
| int[] Numbers = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
foreach (int Number in Numbers)
{
if (Number % 2 == 0)
{
continue;
}
Console.WriteLine(Number);
} |
while/do while
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| string Name = "";
do
{
Console.Write("Enter a Name:");
Name = Console.ReadLine();
if (Name == "Parastratiosphecomyia stratiosphecomyioides")
{
// The animal with the longest Scientific Name???
continue;
}
if(Name != "")
Console.WriteLine("{0} is a good name", Name);
} while (Name != ""); |
partho Google