The compiler compiles a foreach loop into something like a for loop when the foreach is used with an array. And the compiler compile
foreach
for
foreach is internally just a while loop that calls the methods in IEnumerator.
while