While loop C# with Example



While loop C# with 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 largestMetroAreas = GetLargestMetroAreas(4); 
while (largestMetroAreas.MoveNext()) 
{ 
Console.WriteLine(largestMetroAreas.Current); 
} 
Sample output: 
Tokyo/Yokohama 
New York Metro 
Sao Paulo 
Seoul/Incheon 

0 Comment's

Comment Form

Submit Comment