We can skip any repetition of a loop with the command "continue":
/*---------------------------*/
/* C# Example #25: */
/* example25.cs */
/* */
/* "for" with "continue" */
/* */
/* Intro to C#, */
/* Nacho Cabanes */
/*---------------------------*/
using System;
public class Example25
{
public static void Main()
{
int counter;
for (counter=1; counter<=10; counter++)
{
if (counter==5)
continue;
Console.Write("{0} ", counter);
}
}
}
The result of this program is:
1 2 3 4 6 7 8 9 10
We can notice that there is no 5 in it.
No comments:
Post a Comment