Corrected the error of decreasing value of loop variable instead of increasing.