So a step "saving the data" is missing in your explanation. Here either we increment, either we go back to 2 (indefinitly)
So at one moment you need to save the value of this counter or it will be lost. Same remark as above
Giving steps as you did is good, but not when steps are missing. It could just mess with what the OP (or the others) has in mind. I think you should consider editing your post
However, the OP needs to come back with more details if he needs more help