while loop csharp 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: c# while loop
int n = 0;
while (n < 5)
{
Console.WriteLine(n);
n++;
}
Example 3: while c#
int repeats = 0;
bool while = true; //creates a bool variable with the true value
while (while = true) //repeats the code in the curly brackets as long
{ //as the value in the round brackets remains true
repeats++; //increase the value inside repeats
}