When I started programming I knew about the i but not the j. When I encountered my first loop in a loop, I was thinking about how to name the new variable.
I did go for i, ii, iii, iiii and so on. Until my collegue saw it and explained me why that was not the way how we gonna do it.
The one gotcha it has is if you forget to add the third i to iii, then you won't get a reference error due to mistyping your variable. You will unexpectedly get the value of the previous iterator!
In a similar vein to i and ii is i1 and i2, which is ugly as hell but gives you all the benefits of the "Roman numeral" approach without the difficult-to-debug gotcha just waiting to happen.
View all comments
2
u/SpinatMixxer Jun 06 '20
When I started programming I knew about the i but not the j. When I encountered my first loop in a loop, I was thinking about how to name the new variable.
I did go for i, ii, iii, iiii and so on. Until my collegue saw it and explained me why that was not the way how we gonna do it.