In your outer for-loop you use you use i as loop-index. The way matlab has implemented things this is done (IIRC) such that there will be an array with loop-index-values that the loop-variable will step through. This has precedence, so this differs from for example C where the loop simply increments until the interrupt-condition. You might have to code this differently.
First time you fall into the while-loop you will start with some value of i, lest say 5, it will be incremented to 10, then next time through the for-loop i will be set to the next value of the index-array, i.e. 6, and then proceed with that.
The simplest way to implement this snippet to behave in the C-way might be to change the outer for-loop to a while-loop and just make sure the incrementing of i behaves as you want.