Click to See Complete Forum and Search --> : Naming incrementing variables


bt-nd
04-10-2003, 03:03 PM
I typically use i as my primary counter and then j for a second loop if it is nested within the first, etc, etc.

1) Is there a typeical Javascript naming convention for the counters or incrementers used in loops?

2) Is there any problem whatsoever in Javascript with using these same counters over and over in the same script if they are in separate loops and not nested?

I have never had a problem with this, but I would like to know what, if any, potential problems might pop up.

many thanks,

BT

Jona
04-10-2003, 03:07 PM
Um, no. If you have 2 nested for() loops, make sure that the variable looping is not the same as the other one. If you have 2 for() loops, but they are not nested, and you do not need to go back to the first, you can re-use the variable you used in the first loop. (Although, I'm not sure whether or not it will cause an error, I don't think it will.)