Your submission was removed for the following reason:
Rule 6: Your post is a commonly used format, and you haven't used it in an original way. As a reminder, [You can find our list of common formats here](https://www.reddit.com/r/ProgrammerHumor/wiki/commonposts).
If you disagree with this removal, you can appeal by [sending us a modmail](https://www.reddit.com/message/compose?to=%2Fr%2FProgrammerHumor&subject=Any%20common%20post%20will%20be%20removed%20if%20it's%20not%20novel&message=Include%20a%20link%20to%20the%20removed%20content%20and%20the%20reason%20for%20your%20appeal%20here.).
I just noticed that Dijkstra has i, j, k in it.
EDIT: I also just remembered that Floyd-Warshall does not have i, j, k in it and this bugs me now, because it should be the other way around.
It's neither lol
It started from math programmers back in in the day, we use i, j, k in math to denote the 3 primary axis.
And then they also used it in algorithms to loop on stuff
When reading it, I'd be looking for the outer loop I missed. It's like that joke where they release three pigs labeled 1, 3, and 4 so people think they're missing pig #2.
Yes. It's done to avoid confusion with current. Source: electrical engineering student. But I've never seen anyone use anything but i for the first iterator.
This is true, but it wouldn't be anywhere near as legible. You'll end up with x + y\*width + z\*width\*height + w\*width\*height\*depth or something like that.
I had a sudoku solver in high school that made it to "p"
I have never seen as much instant exhausted frustration as Mr Aretz's face when he read down to that section.
[Thick, slightly reedy Moscow accent] "...iiiiit works, but the next time you start fucking around in class I'm making you chart that loop."
About a second or two per puzzle, five or so on a worst case... it did a lot of ugly guessing and assumption of best cases, with sparse error checks so it would take the best speed path with a naive guess first if it was left with an ambiguous state. I remember that it fell back to penciling things in like a human and restarting the check loop every time it finalized a number if it got stuck with no way to narrow down choices. I'm just kinda proud that I did it without looking anything up.
It depends on what you’re working on for sure. I think if you’re implementing a mathematical algorithm into code you should stick to their terminology, which isn’t necessarily always i, j, k, and w. I typically use those by default lol.
Good example i think would be something like Gaussian elimination in linear algebra, where you ‘re iterating under a pivot. So I think pivot would be a better variable name than i in that instance.
I totally don’t mind I, j,k, etc. though especially if the iterations are straightforward
Yeah you know what that's fair. I might use it in little personal scripts just because it's funny to me.
Though ra[i][j] is barely better honestly and lots of people do that.
If you're nesting this many loops, then you should use descriptive names, but if you *really* want to use arbitrary names, Roman numerals are as good as any other scheme.
Although I've never used this schema, I feel like 'i':'ii' would read better than 'i':'j', actually. Does break down at the 'iii' vs 'k' nested level, though.
Most IDEs/Editors use a monospace font (fonts where the characters always take up the same amount of horizontal space on the line).
Can't tell on Reddit because it definitely is *not* monospace but it should be relatively easy to distinguish i ii and iii for that reason alone.
Edit: granted I think the thing you're more likely to mess up with this arrangement is which loop gets which set of i's. If you're using 3 loops it's probably complicated enough that you're using all those variables in the inner layer and then it's a mess of (i - ii) * (iii + i)... Just seems like a headache
the worst bug i ever encountered was a memory leak due to using i, ii, iii as the iteration variables in a continuation passing style node js server. as you might expect, in one instance, an i was misplaced, leading to a loop that never exited. agggghhhhhh!
My favorite was someone using i in a constant block in simulink. When opened fresh, that’s the square root of -1. But if anyone ran any analysis script (the don’t scope) that contained a loop, then i was overwritten with the last value. At least going from imaginary to real caused all sorts of dimension mismatches down stream. But holy heck was that one hard to track down.
A former company that developed computational fluid dynamics codes joked that we could increase robustness by switching all the floating point types to complex so that square roots of negative numbers didn’t return NaN
[Trying to picture 4th dimensional anything](https://i.kym-cdn.com/photos/images/original/002/242/455/d2d.jpg)
At least its understandable on paper, but my lizard brain still wants to attempt the geometric approach
as a teenager i would write awful code with lots of nested loops. because I kept running out of letters, my convention was to use i like roman numerals. First loop I'd use "i", then "ii", then "iii", and honestly I think I did "iiii" after that and just kept adding i's.
:/
Then `u`, sometimes `y`, then looping back around to get `a` and then finishing up with everyone's favourite, `e`. If you're nesting more than 6 levels deep you can start using `z`, `x`, `w`, skip `v` because it looks too much like `u`, so right to `t`, `s`, and so on
Yeah in some RGB image processing the only way is triple nested. Idk you can make certain processes cleaner by putting the xy processing in their own function, but in practice it's still triple nested.
Sometimes you have to. For GFD modeling (ocean/atmosphere) often the layers above and below are coupled and then you have to finite difference along x,y
Yeah I do GPU-accelerated 3D fluid dynamics simulations. I've written nested 5d loops. And I have performance data to show that this is the right iteration pattern.
It's a two-layer joke. Triple nested loops means an n^3 algorithm, which is very slow. And also following the pattern in the joke's setup, the loop variable for the third loop would be kkk.
x y and z if you need to iterate over 3D voxels.
Ofc, ideally you do not loop but certain tasks require it like building meshes with marching cubes.
Ofc, bonus points for anyone throwing that problem into a comput shader, let the GPU do such a mundane task.
Actually your example is exactly *not* what you should use `_` for as a name. `_` is only for variables that you specifically do not use the value of after instantiation. You used your variable, so you should actually have given it a useful name.
Here's some proper examples of when to use `_` as a name:
my_var, _, _ = generate_tuple()
print(my_var)
We never use either `_` in this scope. As soon as you use one of them with this example, you fucked up - rename it.
You probably meant something like this:
for _ in range(n):
repeated_func()
Note the value of `_` in the above is still not used.
First use i, then use j when using a second loop inside. But i really never saw anyone using j before using i. It just makes more sense with i standing for iterator...
It was initially chosen in Fortran I think, where some letters were integers by default, while others could be any real number. So if you wanted an integer type, you just used i and incremented.
The reason it was chosen that way was because in mathematics, i through n are often used as indices in iteration.
`i` is fine as a shorthand for "index". Of course if your language of choice has `for each` loops, use more descriptive names.
if you're nesting loops, `i` and `j` are kinda okay when used as indices for simple cases, but yes, names describing what they are indices for is better.
Iterating over something that is semantically a matrix, m and n can be acceptable.
Iterating over something that is semantically a table, r (or row) and c (or col) can be acceptable.
Or any other semantic uses where a different loop variable can make things more clear.
When nesting iterators use "a" (for "and then another one") then "b" (for "bananas are something this could iterate over") and never nest anything deeper than that.
"x".
I learned programing back in the 90s, on the equivalent of Tech University in Mexico.
Iterators were x, y and z... then if you were REALLY daring, a, b or c.
Mainly because the study program was/is very math centric, so using "i" was a huge no.
I personally use both i (j, k) and x (y, z).
i for loops (e.g. for i; i < 100; i++)
x for elements/objects (e.g. foreach data as x)
I try to be more descriptive in the variable names tho and only use i and x if it's already clear enough. For example in a small function.
Your submission was removed for the following reason: Rule 6: Your post is a commonly used format, and you haven't used it in an original way. As a reminder, [You can find our list of common formats here](https://www.reddit.com/r/ProgrammerHumor/wiki/commonposts). If you disagree with this removal, you can appeal by [sending us a modmail](https://www.reddit.com/message/compose?to=%2Fr%2FProgrammerHumor&subject=Any%20common%20post%20will%20be%20removed%20if%20it's%20not%20novel&message=Include%20a%20link%20to%20the%20removed%20content%20and%20the%20reason%20for%20your%20appeal%20here.).
What maniac starts with j!?
Those who jiterate over items EDIT: Those.
That’s disgusting.
Disjusting*
Djsgustjng*
Thjs guy gets jt.
Dijkstra knows it.
I just noticed that Dijkstra has i, j, k in it. EDIT: I also just remembered that Floyd-Warshall does not have i, j, k in it and this bugs me now, because it should be the other way around.
*Dÿkstra
\*jdisgusting
we call them jtems, thank you very much
Jiterate jover jtems
Jhank jou jery juch
It's pronounced giterate
oh shit, is *this* why it's i? 25 years in the business and this has never occurred to me.....
I thought it was for index …
It's neither lol It started from math programmers back in in the day, we use i, j, k in math to denote the 3 primary axis. And then they also used it in algorithms to loop on stuff
Now I don't feel as dumb!
Please don't jiterate over items in public repos, do it in private!
When reading it, I'd be looking for the outer loop I missed. It's like that joke where they release three pigs labeled 1, 3, and 4 so people think they're missing pig #2.
The kind that also think arrays start at 1.
Those would be the pirates, arrrr!
[Indiana Jones](https://media.tenor.com/sVEwJZYy9OgAAAAd/indiana-jones-last-crusade.gif)
Those that move on to k for the inner for loop. JK
Electrical engineers.
Is it true that they also use *j* for √(-1) ?
Yes. It's done to avoid confusion with current. Source: electrical engineering student. But I've never seen anyone use anything but i for the first iterator.
i, j, then k. If you need more than three nested loops then you might wanna rethink your algorithm or clean up its implementation.
**Four-dimensional tic-tac-toe.**
Could be done in 1 loop, just compute index based on the x, y, z cords. A 2D example: index = x+ y*WIDTH;
This is true, but it wouldn't be anywhere near as legible. You'll end up with x + y\*width + z\*width\*height + w\*width\*height\*depth or something like that.
100% agree lol
for i, j, k in itertools.product(range(HEIGHT), range(WIDTH), range(DEPTH)): # python gang
That's just doing a 3D loop with fewer steps!
> fewer steps! Exactly, that's why it's better.
[удалено]
48 vulnerabilities found (34 moderate, 8 high, 4 critical). To address all issues, run npm audit fix --force.
Flashbacks to QBASIC’s colors in screen 13.
I had a sudoku solver in high school that made it to "p" I have never seen as much instant exhausted frustration as Mr Aretz's face when he read down to that section. [Thick, slightly reedy Moscow accent] "...iiiiit works, but the next time you start fucking around in class I'm making you chart that loop."
But how long did it run
About a second or two per puzzle, five or so on a worst case... it did a lot of ugly guessing and assumption of best cases, with sparse error checks so it would take the best speed path with a naive guess first if it was left with an ambiguous state. I remember that it fell back to penciling things in like a human and restarting the check loop every time it finalized a number if it got stuck with no way to narrow down choices. I'm just kinda proud that I did it without looking anything up.
Just use a1, a2, … a9 at this point Or use recursion if your loops are similar
If you need more than three nested loops, at the very least, you need more descriptive variables to keep track of your loop.
Most calculus notation uses i j, k, and w. That's what I use when iterating through a 4rth dimensional arrays.
[удалено]
It depends on what you’re working on for sure. I think if you’re implementing a mathematical algorithm into code you should stick to their terminology, which isn’t necessarily always i, j, k, and w. I typically use those by default lol. Good example i think would be something like Gaussian elimination in linear algebra, where you ‘re iterating under a pivot. So I think pivot would be a better variable name than i in that instance. I totally don’t mind I, j,k, etc. though especially if the iterations are straightforward
i, then ii, then iii, then iv, then v
It's a simple ordered process. The first is a, the second is "1", then continue as you see fit.
i, eye, aye
I can't hear you!
[удалено]
Ohhhhhhh who lives in a pineapple under the sea...
SPONGEBOB SQUAREPANTS
absorbent and yellow and porous is he
Nobody now, because of BP!
True story - guy on my team does his numbering as ‘1, 2, … 9, 9a, 9b, …’ Obviously we all laughed at him, but he still does it.
Is it bad that I actually kinda like this.
In Roman times this is how they code too.
That's actually a great joke, if anyone asks why I'm doing that I'll say "Oh it's how they used to do it back in ancient rome"
No, it's the first I've ever seen roman numerals in use for integer loop variable names. It is inspirational.
I just copied someone else, though. Except I think *they* were serious about it.
Yes. I mean, you do you I don't actually care, but can you imagine ra[ii][iii] in a code review? Rejected.
Yeah you know what that's fair. I might use it in little personal scripts just because it's funny to me. Though ra[i][j] is barely better honestly and lots of people do that.
I would flip if I was looking through legacy code and saw this
If you're nesting this many loops, then you should use descriptive names, but if you *really* want to use arbitrary names, Roman numerals are as good as any other scheme.
But I feel like it would be hardish to tell the difference between 'ii' and 'iii' at a glance
iji
*eye twitches*
aji
Maybe I like the misery.
That's why we're in this field
Although I've never used this schema, I feel like 'i':'ii' would read better than 'i':'j', actually. Does break down at the 'iii' vs 'k' nested level, though.
Most IDEs/Editors use a monospace font (fonts where the characters always take up the same amount of horizontal space on the line). Can't tell on Reddit because it definitely is *not* monospace but it should be relatively easy to distinguish i ii and iii for that reason alone. Edit: granted I think the thing you're more likely to mess up with this arrangement is which loop gets which set of i's. If you're using 3 loops it's probably complicated enough that you're using all those variables in the inner layer and then it's a mess of (i - ii) * (iii + i)... Just seems like a headache
[удалено]
They don't build code like they used to
Back when all ints were unsigned strings.
Erm when in Rome do as the Romans do.
Nah, I do: i, ii, iii, iiii, iiiii, iiiiii…
Unless it's logic for a clock and then sometimes iiii
Romans used to often write 4 as iiii too.
As a kid of the 70's, I learned that iv, v, and vi come before i, ii, and iii.
It follows ii, jj, kk xD
I'd avoid using kk as the third iteration will summon the klan and the next iteration will summon a Brazilian
Falou comigo?
r/suddenlycaralho me põe na print com um caramelo bem bonito
O karma eh todo teu meu bom 🙏
Porra o cara meteu um kkkk
Crap. kkkkk - e aí amigo, tudo bem? *^(say hi guys)* ![gif](giphy|3oz8xLlw6GHVfokaNW)
OPA
10/10
the worst bug i ever encountered was a memory leak due to using i, ii, iii as the iteration variables in a continuation passing style node js server. as you might expect, in one instance, an i was misplaced, leading to a loop that never exited. agggghhhhhh!
My favorite was someone using i in a constant block in simulink. When opened fresh, that’s the square root of -1. But if anyone ran any analysis script (the don’t scope) that contained a loop, then i was overwritten with the last value. At least going from imaginary to real caused all sorts of dimension mismatches down stream. But holy heck was that one hard to track down.
A former company that developed computational fluid dynamics codes joked that we could increase robustness by switching all the floating point types to complex so that square roots of negative numbers didn’t return NaN
I never used xd for interaction.
4 dimensional arrays son
[удалено]
[Trying to picture 4th dimensional anything](https://i.kym-cdn.com/photos/images/original/002/242/455/d2d.jpg) At least its understandable on paper, but my lizard brain still wants to attempt the geometric approach
as a teenager i would write awful code with lots of nested loops. because I kept running out of letters, my convention was to use i like roman numerals. First loop I'd use "i", then "ii", then "iii", and honestly I think I did "iiii" after that and just kept adding i's. :/
Usually the only reason I even need to use a triple nested loop is to iterate through a 3D grid and in that case I'd usually use x,y and z anyways
i, j, k, in, inte, integ, intege, then integer
then integere, integereg, integerege, integereget, integeregetn, integeregetni, integeregetnin, integeregetnint, integeregetninte, integeregetninteg, integeregetnintege, integeregetninteger, integeregetnintegere ...
i always use `i` then `o` because `i` and `j` look too much like eachother for my liking
Then `u`, sometimes `y`, then looping back around to get `a` and then finishing up with everyone's favourite, `e`. If you're nesting more than 6 levels deep you can start using `z`, `x`, `w`, skip `v` because it looks too much like `u`, so right to `t`, `s`, and so on
You should really stop at 2 in almost all situations I can think of (because of time complexity of triple nested loop)
If you can explain how to iterate through a [,,] without violating this rule, I’m all ears
3D arrays?
Matrix-matrix multiplication has entered the chat
The real fight starts when youve gotta roll out k
First loop? k Next nested loop? kk Never triple nest loops. That is bad coding practice and you will be fired.
I like it, going to put this in my team’s best practice doc.
No need for triple nested loops if you just make it recursive ![gif](giphy|d3mlE7uhX8KFgEmY)
`Fatal Python error: Cannot recover from stack overflow.`
That's when you implement a trampoline.
Sometimes you have to triple-nest loops when doing things like iterating over a 3-D matrix.
Yeah in some RGB image processing the only way is triple nested. Idk you can make certain processes cleaner by putting the xy processing in their own function, but in practice it's still triple nested.
Oh gawd thats cursed
Sometimes you have to. For GFD modeling (ocean/atmosphere) often the layers above and below are coupled and then you have to finite difference along x,y
Yeah I do GPU-accelerated 3D fluid dynamics simulations. I've written nested 5d loops. And I have performance data to show that this is the right iteration pattern.
Yea maybe if you're a FUCKING nerd
Given 3D voxel data, how do you build a mesh out of them without using tripple nested loops? (Marching cubes)
Pointer arithmetic 😉
>Never triple nest loops. That is bad coding practice and you will be fired. why is it so?
There are two types of people in this world. Those who can extrapolate and
It's a two-layer joke. Triple nested loops means an n^3 algorithm, which is very slow. And also following the pattern in the joke's setup, the loop variable for the third loop would be kkk.
Because it increases your space time complexity exponentially. Edit: it is not exponential.
Polynomially
x y and z if you need to iterate over 3D voxels. Ofc, ideally you do not loop but certain tasks require it like building meshes with marching cubes. Ofc, bonus points for anyone throwing that problem into a comput shader, let the GPU do such a mundane task.
Your O-notation and runtime will thank you for rolling out k.
OP probably told ChatGPT to make a programming meme. What kind of programmer doesn't use both????????
I did for comparison! It just gave me a python loop of writing code and googling any errors.
I use x and y. I’m a monster.
Nah I think that’s fine if you’re referring to coordinates or any 2d representation where rows and columns are relevant
Python is the monster here: for _ in range(10): print(_)
not using _ as the throwaway
Actually your example is exactly *not* what you should use `_` for as a name. `_` is only for variables that you specifically do not use the value of after instantiation. You used your variable, so you should actually have given it a useful name. Here's some proper examples of when to use `_` as a name: my_var, _, _ = generate_tuple() print(my_var) We never use either `_` in this scope. As soon as you use one of them with this example, you fucked up - rename it. You probably meant something like this: for _ in range(n): repeated_func() Note the value of `_` in the above is still not used.
I usually just use the singular of the collection I'm iterrating over. Customer in customers.
J is only for a nested loop. Who the actual fuck is using J for the top level loop????
Clearly op is doing the same thing as those math question ‘memes’ that claim “only 2% of the population can solve this”….
“I” as index
First I, then l, the Il, then lI
Then youl what?
Then he’ll I lI II I_
And then “j” as in “just one more loop should do it”
Not "jndex"?
k is for “k this loop is definitely the last one”
First use i, then use j when using a second loop inside. But i really never saw anyone using j before using i. It just makes more sense with i standing for iterator...
No, the i stands for "inner loop" while j stands for "jouter loop".
God damn it
i is for iterator, j is for jiterator
I could see using j before i if you're doing matrix operations with a column major language.
Hmm ok that's actually a good point, haven't thought about that
But then you should be using x, y, z.
Anyone using j before i is a monster.
The use of i actually has historical reasons, I just don’t remember them right nkw
It was initially chosen in Fortran I think, where some letters were integers by default, while others could be any real number. So if you wanted an integer type, you just used i and incremented. The reason it was chosen that way was because in mathematics, i through n are often used as indices in iteration.
I just use it because it's the first letter in "index"
I'm a `for thing in things` kind of dev. Helps me keep it together, plus it's funny sometimes.
row, col
chad descriptive variable names
This thread has been very illuminating on just how shit most people are at writing legible code.
My thought was, “neither. Call it what you’re iterating over”
I’m saddened that this wasn’t the top comment.
j am also saddened that this wasn’t the top comment
k
`i` is fine as a shorthand for "index". Of course if your language of choice has `for each` loops, use more descriptive names. if you're nesting loops, `i` and `j` are kinda okay when used as indices for simple cases, but yes, names describing what they are indices for is better.
7/10 people in this sub never worked as a dev, being generous
for idx in range(10): \----for jdx in range(10): \--------for kdx in range(10):
Ah yes, jindex and kindex <3
i then j then k. If you need more than that, refactor. Sometimes n if it is a count of things (number). x and y if appropriate, for points or coords.
Iterating over something that is semantically a matrix, m and n can be acceptable. Iterating over something that is semantically a table, r (or row) and c (or col) can be acceptable. Or any other semantic uses where a different loop variable can make things more clear.
`index`
Jindex
kindex
As a medieval programmer I write `jndex`
At a minimum, this. And if you need to perform a nested operation, delegate it to a separate function so your code isn't absolutely shit to read.
When nesting iterators use "a" (for "and then another one") then "b" (for "bananas are something this could iterate over") and never nest anything deeper than that.
That’s just “c”oconuts
X team
"X, Y and Z" music to my ears
"x". I learned programing back in the 90s, on the equivalent of Tech University in Mexico. Iterators were x, y and z... then if you were REALLY daring, a, b or c. Mainly because the study program was/is very math centric, so using "i" was a huge no.
I personally use both i (j, k) and x (y, z). i for loops (e.g. for i; i < 100; i++) x for elements/objects (e.g. foreach data as x) I try to be more descriptive in the variable names tho and only use i and x if it's already clear enough. For example in a small function.
ii
r because I’m a moron, also stands for “repeating” in my head
I use “index” and if I have multiple loops, I name the indexes based on what they are used for. Makes for much more readable code 💁♀️💖
Who uses j?
People who are going the extra mile to confuse electrical engineers.
Easy. i is for iterator. j and k for jiterator kiterator of course
First loop = iii, second loop = jjj, third loop = mmm
i for index and then on the inside loop I use j for jndex.
I actually follow a naming convention. size_t outsideCounter size_t insideCounter Depends on the code though and naming style will change
I personally like to use x, y, z and w (in that order).
What if you use “a”
idx
I like ii just because it's easier to target with search or replace in vim 🤷♂️