C# break and continue
Last modified: June 28, 2021static void Main(string[] args)
{
var numbers = new List<int>() { 1, 4, 6, 9 };
foreach(var number in numbers)
{
if(number.Equals(4))
{
break; //it will break the whole loop meaning when it reach 4 whole loop exit.
}
Console.WriteLine(number);
}
foreach (var number in numbers)
{
if (number.Equals(4))
{
continue; //it will break current sequence, not the whole loop.
}
Console.WriteLine(number);
}
}