Why does the LED turn on after the while loop becomes false?

Isn't that undefined behavior according to the standard? I am no expert but

ledMode = (ledMode+1) % 8;

will always work