View Single Post
Old 11-15-2004, 01:38 PM   #3 (permalink)
scott_p_1
Crazy
 
Initializing the variables in the for statement gives the variables a bit different scope. If you define the variable in the for statement, the variable will only be accessible in the loop.

You normally don't need your loop counter value to be used outside the loop (there might be the odd case where this might make sense).

In most cases, yes, it will be better to keep variable initialization in the for statement. It will keep your code nice and readable.
scott_p_1 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54