I added code tags to your code: always use them. Doesn't it look better now. Unfortunately you have not completely indented your code, which makes it difficult to see where your loops start and end. I think that you will see that result is in fact reset to 1 each iteration of the outer loop, if you go back and correct the indentation.