while loop syntax c# code example
Example 1: c sharp exit while loop
// To forcibly exit a while loop use 'break'
while (true)
{
// Do something
if (conditional)
{
break;
}
}
Example 2: while in c#
using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
int i = 0;
while (true)
{
Console.WriteLine("i = {0}", i);
i++;
if (i > 10)
break;
}
}
}
}