Your for loop does nothing. When i is not volatile, the compiler sees that changing i serves no purpose, so it optimizes away the whole for loop.
By declaring i volatile, the compiler is told that the variable might be altered by external action during the for loop, so the loop can't be optimized away.