using System;
using System.Collections.Generic;
// see: https://stackoverflow.com/a/231945/1016343
public class Program
{
public static void Main()
foreach (var e in GetEnumerator()) { e.Dump(); }
}
public static IEnumerable<int> GetEnumerator()
int i = 0;
while (true)
if (i < 5)
yield return i;
else
// note that i++ will not be executed after this
yield break;
i++;