Conditional Statement

I was wondering what the rules are for declaring variables which you would increment say in an for loop. I tried to declare a variable outside the for loop, and then increment it within the loop but that didn’t work. If there is a tutorial anyone knows of that would be great too.