It's all the matter of decompiler. Next code is produced by decompiling mscorlib assembly's method ElementAt
by DotPeek:
public static TSource ElementAt<TSource>(this IEnumerable<TSource> source, int index)
//...omitted code for validation
using (IEnumerator<TSource> enumerator = source.GetEnumerator())
{
while (enumerator.MoveNext())
{
if (index == 0)
return enumerator.Current;
--index;
}
throw Error.ArgumentOutOfRange("index");
}
IL instructions doesn't have while
construction. Next code demonstrates this:
while(true)
{
Console.WriteLine ("hi there");
}
is compiled into:
IL_0000: ldstr "hi there"
IL_0005: call System.Console.WriteLine
IL_000A: br.s IL_0000 //unconditionaly transfers control to IL_0000. It's like goto IL_0000; but in IL