Hi Chinna,
One has to watch if the loop result increases or decreases a loop counter.
You need to use backward steps (i--) in this case ==> otherwise a code sometimes works - sometimes ends with error.
In current subject this problem shows according to last rows of modified table.
Jarek