Essential C# Looping  Suggest an edit

While loop

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

Table Of Contents
22 Enum
25 GUID
28 Looping
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close