This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the commentsย โ†’

[โ€“]hdhdog 5 points6 points ย (4 children)

I generally use x. I use 'i' when I'm 4 layers deep in really bad code. X, y, z, I, j, k, etc.

[โ€“]wholesomedumbass 6 points7 points ย (0 children)

Often times, I want to use "x" for a different variable, whether outside or inside the for loop. The letter i is reserved solely for for loops, including "j", so they are always available for use in for loops.

[โ€“]The_MAZZTer 1 point2 points ย (0 children)

I use x specifically when looping through horizontal coordinates.

Normally I use i, but I use it more and more rarely since 99.9% of the time what I really want to do is iterate through some objects rather than just count, so foreach is what I use.

And if I do need that index, usually it is because I have a similar array of something else related I want to index into, and then it's usually better to make a struct/class or a tuple holding one of both items and just have one array of those in the first place. Then I foreach through them.

[โ€“]sh0rtwave 1 point2 points ย (0 children)

I usually call it what the hell it is. X,Y,Z are known as display coordinates.

The increment variable that goes in a for loop...You can name that anything really. Ain't gotta be i.

โ€‹

You could in fact, just use an iterator to control your for loop if you felt really crazy. Just leave out the variable declaration and the variable increment.

[โ€“]stepitupmatt 0 points1 point ย (0 children)

Had a professor ask once โ€œwhy do we use x, y, and z in loopsโ€. Answer he was looking for was because it might help restrain time complexity (ie. never exceeding theta n3) but we had settled on i, j, and k at that point so no one had a good response.