C# Language Looping While loop

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

int n = 0;
while (n < 5) 
{
    Console.WriteLine(n);
    n++;
}

Output:

0
1
2
3
4

IEnumerators can be iterated with a while loop:

// Call a custom method that takes a count, and returns an IEnumerator for a list
// of strings with the names of theh largest city metro areas.
IEnumerator<string> largestMetroAreas = GetLargestMetroAreas(4);

while (largestMetroAreas.MoveNext())
{
    Console.WriteLine(largestMetroAreas.Current);
}

Sample output:

Tokyo/Yokohama
New York Metro
Sao Paulo
Seoul/Incheon



Got any C# Language Question?