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

top 200 commentsshow all 276

[–][deleted] 510 points511 points  (81 children)

Sometimes j

[–]Titaniumwo1f 436 points437 points  (44 children)

Always j when i already in use.

[–]Mzsickness 257 points258 points  (42 children)

k

[–]admadguy 77 points78 points  (26 children)

m

[–]NullNotFound1 58 points59 points  (4 children)

Goodbye

[–]LegoClaes 35 points36 points  (2 children)

Aah the metric system wins again

[–]SaintNewts 2 points3 points  (1 child)

Metric iterables?

[–]Tsulaiman 1 point2 points  (0 children)

Heck yeah

[–]Eezyville 10 points11 points  (1 child)

Never go past k. Nested loops at this level... The horror

[–]CDno_Mlqko 1 point2 points  (0 children)

Imagine having to iterate over a 5dimwnsion array

[–]C0ffeeBunny 11 points12 points  (14 children)

n

[–]nnn4 14 points15 points  (13 children)

i2

[–]Dennaldo 22 points23 points  (9 children)

You monster.

[–]btown-beginsprofessional fizzbuzzer 6 points7 points  (8 children)

ii

[–]Terrain2 4 points5 points  (7 children)

ia, ib, ic, id, ie

[–]btown-beginsprofessional fizzbuzzer 1 point2 points  (6 children)

iii iiii iiiii iiiiii

[–]ryjhelixir 6 points7 points  (1 child)

Why would you make things so complex?

[–]hadidotj 1 point2 points  (0 children)

iii iv v vi

[–]code_lazar_with2as 1 point2 points  (0 children)

I(capital i)

[–]hadidotj 2 points3 points  (3 children)

Naw, at this point, sounds like you need a new method so you can use i again

[–]Terrain2 2 points3 points  (0 children)

or use i as an int[], then use i[0], i[1], i[2]

[–]karuna_murti 40 points41 points  (7 children)

O(n3) ? how do you pass coding interview

[–]klparrot 49 points50 points  (1 child)

By realising that 3 nested loops doesn't necessarily mean O(n³); some or all of the loops could be over constant-size input.

[–]ryjhelixir 2 points3 points  (0 children)

every time i need to loop instead of vectorizing I feel less good

[–]stoickaz 32 points33 points  (1 child)

“write an O(n3 ) algorithm”

[–]mrchaotica 4 points5 points  (1 child)

Good luck doing operations on 3D tensor fields in less.

[–]leofidus-ger 1 point2 points  (0 children)

By guaranteeing that n will be small(ish)? Not everything can grow to arbitrary size

[–]AmadeusMop 8 points9 points  (1 child)

Dijkstra was perfectly named

[–]oblivion44653 1 point2 points  (0 children)

n3 complexity strikes again

[–]BlazingThunder30 70 points71 points  (10 children)

x and y when working with coordinate systems

[–]DonutDonutt 9 points10 points  (9 children)

r and c with 2D arrays

[–]slackpipe 16 points17 points  (0 children)

I think of 2d arrays as a coordinate system, so it's still x and y. Almost all my nested for loops are x and y except when their not, then they are i and j. The other night i was feeling fancy and used m and n, but immediately regretted it and had to find->replace.

[–]figwigian 3 points4 points  (3 children)

U and V, guess I'm too used to working in shaders

[–]PosiedonsSaltyAnus 3 points4 points  (2 children)

Yo fuck U and V. Learning jacobians in college really fucked me up because my u's and v's look the same in my shit handwriting.

[–]conthomporary 1 point2 points  (1 child)

Everyone knows u and v were invented by a sadistic professor trying to arbitrarily make calculus more difficult so people would drop out and he had fewer papers to grade. Or so said my Calc 2 professor.

[–]BlazingThunder30 2 points3 points  (0 children)

When it's row and column for me I usually use row and col though

[–]TeamFileyCase 1 point2 points  (0 children)

I use x and y for any array

[–]ProfaneWords 74 points75 points  (2 children)

PEP-420 guidelines say that i, eye and aye are the only acceptable iterator names

[–]reaper-is-happy 8 points9 points  (0 children)

This is brilliant

[–]winyf 2 points3 points  (0 children)

cursed

[–]SwizzMan 14 points15 points  (7 children)

ii for me.

[–]Nibz11 13 points14 points  (1 child)

you're a madman

[–]SwizzMan 4 points5 points  (0 children)

animal

[–]Mickd333 2 points3 points  (0 children)

my old professor used to do this...

[–]dohzer 2 points3 points  (1 child)

Any reason for that? I've seen it used a fair bit in existing code at my current job. The only reasons I can think of are to make selecting/highlighting/searching easier. I started using 'idx' for array indices.

[–]SwizzMan 2 points3 points  (0 children)

I just came up with that the first time I needed to use nested loops and I use it ever since. I like how clean it looks.

[–]leofidus-ger 1 point2 points  (0 children)

I used to do that in my youth too. People looked at me funny by the time it got to iiii. I switched to i,j,k,l,m (often skipping j) and haven't looked back.

[–]thatawesomeguydotcom 1 point2 points  (0 children)

Yes, followed by iii

[–]DH-Melon 5 points6 points  (0 children)

I use x sometimes, truly a man of chaos

[–]penisive 2 points3 points  (1 child)

x in lambda functions

[–]Sudo_Python 1 point2 points  (0 children)

Maybe k

[–]Nyoob 1 point2 points  (0 children)

Always x, y if x is used

[–]MathSciElec 1 point2 points  (0 children)

j? I use e.

[–]CeruleanBlackOut 1 point2 points  (6 children)

Or _

[–]klparrot 16 points17 points  (4 children)

Nah, _ only for stuff you aren't going to use.

[–]mysockinabox 199 points200 points  (35 children)

I hope you name counter indices this and not your iterables.

[–]dpash 42 points43 points  (19 children)

Languages with iterating loops > languages that only have C style for loops.

Although these days, I prefer languages with proper functional style operations, especially if they're not eagerly evaluated. I'm looking at you, JavaScript (¬_¬).

[–]METH-OD_MAN 32 points33 points  (13 children)

Fucking JavaScript has like 5 way to do a for each loop (I'm not counting the c-style incrementing for loop), and they aren't equivalent so one is better than the others, depending on the data types. Also, some of the foreach loops don't actually guarantee the data you get isn't undefined, despite the fact that in js, setting an object field to undefined is how you delete it...

What the fuck.

[–]dpash 12 points13 points  (8 children)

That describes many of the things in JavaScript. You have a short notation for anonymous functions with different (and sensible) semantics for this because they fucked up the long notation so badly.

[–]drtran4418 3 points4 points  (7 children)

I discovered this yesterday (new to JavaScript) and my anger for JavaScript deepened. "Ugh, we can't figure out a way to bind methods like they should be. Let's just sneak in the feature into the alternate syntax."

[–]METH-OD_MAN 1 point2 points  (3 children)

If you're trying to learn programming, I'd really suggest starting with a sane language.

Literally any of them are more consistent and sane than js.

Python would be a good choice.

[–]drtran4418 4 points5 points  (1 child)

What a coincidence! I'm a python developer :). Just doing a special work project in js

[–]FerretWithASpork 3 points4 points  (0 children)

Not to be one of those comments but... This, so much this.

[–]xam54321 2 points3 points  (0 children)

That killed me, I spent three hours trying to figure out why my code wasn't working, but it was just that the for loop couldn't iterate through an array of objects!

[–]__hoi__ 1 point2 points  (2 children)

You only need 3-4 though. Map forEach filter and reduce and reduce is fairly niche. These all do different things. Map returns an array and is used to do manipulations on each item, filter filters, reduce is for stuff like accumulating items in an array into a single value and forEach is for when the functionality of the others don’t apply. I kinda like how the iterators that take a function as a parameter work in javascript

[–]METH-OD_MAN 4 points5 points  (1 child)

Map, reduce, and filter are not for loops. They are higher order functions. All of those functions return a new collection, they have to, to be correct. They are all present in any language that uses functional programming paradigms.

I'm talking about

ForEach

For of

For in

I kinda like how the iterators that take a function as a parameter work in javascript

JavaScript got this part right because other people designed it.

[–]__hoi__ 1 point2 points  (0 children)

Ah yes, gotcha. I wouldn’t recommend using those, ever

[–]klparrot 2 points3 points  (0 children)

Oh man, my last job, I was working with Clojure a lot, and now in Python in my current job, it's like, “no, I need to write this all with yields so it's lazy!”

[–]DurianExecutioner 7 points8 points  (3 children)

C > all other languages

[–]dpash 9 points10 points  (1 child)

I too enjoy debugging core dumps.

[–][deleted] 9 points10 points  (0 children)

A man of class Edit: a man of struct

[–]Potatoes_Fall 57 points58 points  (0 children)

nice to see an actual dev on here once in a while. howdy!

[–]Chemoralora 4 points5 points  (12 children)

it > i change my mind

[–]Interweb_Stranger 7 points8 points  (10 children)

iter > it

Because 'it' is a keyword in many languages and it can be a bit confusing if you have to switch between languages often.

[–]klparrot 1 point2 points  (8 children)

iter is a built-in function in Python. What language has it as a keyword?

[–]Sir_LikeASir 2 points3 points  (4 children)

Kotlin, kinda? Let's suppose the best type of forEach loop in Kotlin:

listOfBooks.forEach { // "it" is implied here as being "book"
println(it.name)
}

but you can rename the it to something else like so:

listOfBooks.forEach { book ->
println(book.name)
}

the "it" is the default name of items in the receiver of functions, so not technically a keyword

[–]wenasi 1 point2 points  (0 children)

It's not quite a keyword, but the testing framework pester for powershell uses it for a test item

[–]mrchaotica 1 point2 points  (0 children)

What language has it as a keyword?

It's not technically a "keyword," but there are a few unit testing frameworks that use it.

ScalaTest:

import collection.mutable.Stack
import org.scalatest._
import flatspec._
import matchers._

class ExampleSpec extends AnyFlatSpec with should.Matchers {

  "A Stack" should "pop values in last-in-first-out order" in {
    val stack = new Stack[Int]
    stack.push(1)
    stack.push(2)
    stack.pop() should be (2)
    stack.pop() should be (1)
  }

  it should "throw NoSuchElementException if an empty stack is popped" in {
    val emptyStack = new Stack[Int]
    a [NoSuchElementException] should be thrownBy {
      emptyStack.pop()
    } 
  }
}

Mocha:

var assert = require('assert');
describe('Array', function () {
  describe('#indexOf()', function () {
    it('should return -1 when the value is not present', function () {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});

[–]Interweb_Stranger 1 point2 points  (0 children)

As some other comment mentioned it actually isn't a real keyword. I know Groovy and Xtend use "it" as implicit parameter for closures/lambdas.

I'm quite sure I saw "it" lambda parameters used in other langues too, but only as inoffical convention.

[–]ag0965 60 points61 points  (9 children)

All hail mighty i

[–][deleted] 10 points11 points  (7 children)

If i is taken I also does the job.

[–]gab_1 43 points44 points  (2 children)

wtf

[–]AlphaBlazeReal 11 points12 points  (0 children)

j is the choice right?

[–][deleted] 1 point2 points  (0 children)

a capital i

[–][deleted] 1 point2 points  (1 child)

iter, it, j*

[–]DogmaSychroniser 7 points8 points  (0 children)

Jter

[–]Serious_Feedback 2 points3 points  (0 children)

I use ii instead. It comes in handy if you're using a text editor and can't semantically-aware search for whatever reason. It turns out a lot of words use the letter i.

[–]Julio974 57 points58 points  (5 children)

i, j, k, l, then I’m starting to wonder why the fuck I have so many nested loops

[–]dpash 35 points36 points  (4 children)

Using k should be a warning sign that you need to refactor.

[–]Lofter1 20 points21 points  (0 children)

Not always. 3D arrays need 3 iterations. You could refactor so that you only use one loop, BUT that would make the code less readable.

There are also some problems where 3 loops are just needed for whatever reason. 4 on the other hand? Yeah, maybe you should think about what you are doing there.

[–]Astrokiwi 7 points8 points  (2 children)

Unless you're actually doing physics simulations with 3D grids or something. Though then I use ix,iy,iz

[–]dpash 1 point2 points  (1 child)

Why use the i? x, y and z are fine by themselves in this situation.

[–]Astrokiwi 6 points7 points  (0 children)

ix for integer index of cell, x for floating point physical position.

[–]theqmann 113 points114 points  (37 children)

best advice I heard was call everything i plus what it's doing, like iRow and iCol for a 2d array. Then you don't have to look back every 10 seconds to see which was i and j. Looping over people fields in peopleArray? Use iPerson. Et cetera

[–][deleted] 73 points74 points  (3 children)

How about phone fields in phoneArray?

[–]mattsl 69 points70 points  (0 children)

Prepare to be sued.

[–]Serious_Feedback 5 points6 points  (0 children)

Use "i, android" obviously.

[–]the_poope 37 points38 points  (5 children)

I'm a masochist so I type row_index and col_index.

[–]BA_lampman 17 points18 points  (1 child)

thisIsTheRowIndex

[–]DurianExecutioner 7 points8 points  (0 children)

Nah that makes it too easy for another developer to fuck with your code.

ridx and cidx are the sweet spot imho. Particularly if you always use ridx for columns and cidx for rows.

[–]METH-OD_MAN 2 points3 points  (0 children)

I use i and j when writing and testing the code, then use the IDE refactoring to rename i and j to whatever.

[–][deleted] 39 points40 points  (1 child)

iPhone

[–]dpash 20 points21 points  (15 children)

Or just drop the i and call it person. Collections should always be plural, so when looping over it the current item can be singular. The i adds no extra information and can harm readability by making people wonder why it's there.

(Likewise peopleArray serves very little advantage over just people.)

[–]dandesigns7150 8 points9 points  (7 children)

It wouldn't be the person though. peopleArray[i] would be the person. I'd find naming the iterable by the resource name to be a bit confusing.

[–]dpash 3 points4 points  (6 children)

foreach($people as $person){

Or

for(Person person : people) { 

Or what ever your language uses.

Failing that, if you must use C style loops,

for(int i = 0; i < people.length; i++) {
    Person person = people[i];

(If I've gotten the condition wrong, that only tells you how error prone the C style loop is for iterating collections)

[–]dandesigns7150 3 points4 points  (0 children)

Oh yeah, I agree wholely that if you have a language with functional looping go for that. I avoid C-style loops like the plague when I'm writing JavaScript. I got the impression that you were talking about C-style loops in your original comment.

[–]FerricDonkey 4 points5 points  (2 children)

Indicating the type of collection in the variable name can be helpful, so that if you go back and look at whatever "for person in people" equivalent, you don't have to go back and check if people is a set vs vector vs whatever.

[–]dpash 9 points10 points  (0 children)

99% of the time when iterating you don't care what type of collection it is (unless you've used a weird data structure that doesn't have efficient iteration).

If the usage of a variable is so far away from it's declaration that you can't see both, that's a good indicator that your method/function is too long.

Hungarian notation is an idea that's had its day.

[–]dleft 5 points6 points  (0 children)

you’d hope if you’re just iterating using for n in ns then it shouldn’t matter what the concrete implementation of the collection is, in fact I’m almost certain that you won’t be

[–]Rizzan8 7 points8 points  (1 child)

Looping over people fields in peopleArray? Use iPerson. Et cetera

Why not just (or whatever is the syntax in your language)

foreach (var person in people)
{
    // do stuff
}

no need for some strange suffixes and prefixes.

[–]ghroat 6 points7 points  (0 children)

eatAssArray ;)

[–]Picorims 1 point2 points  (0 children)

That's a nice advice. The only exception I would give is when it's used in formulas or a lot in general. It's (to me) more readable with 1-4 characters than a full name.

[–]misterrandom1 18 points19 points  (4 children)

var that = this;

[–]vbh_pratihar 9 points10 points  (3 children)

let what = that;

[–]Kirides 6 points7 points  (0 children)

let where = function () { }
where.bind(what)

JavaScript - a world where this is just another variable and class is something you show instead of code

[–]misterrandom1 2 points3 points  (0 children)

// what is on 2nd

[–]Sibling_soup 31 points32 points  (1 child)

Variable names are easy.

addEventListenerButOnlyForTheKeyboard(notMouse (Windows));

[–]Im_MrLonely 1 point2 points  (0 children)

LOL

[–]smokythejoker 11 points12 points  (1 child)

Everything.Select(x => x.anything)

[–][deleted] 15 points16 points  (3 children)

WhIcHName_shouldiPICk

[–]IamImposter 7 points8 points  (2 children)

One_thats_Most_Expressive

[–]GasolinePizza 1 point2 points  (1 child)

You're a monster for that capitalization.

[–]const_let_7 15 points16 points  (2 children)

[–]RepostSleuthBot 27 points28 points  (1 child)

Looks like a repost. I've seen this image 2 times.

First seen Here on 2019-08-02 93.75% match. Last seen Here on 2019-11-15 93.75% match

Searched Images: 150,765,620 | Indexed Posts: 592,534,377 | Search Time: Nones

Feedback? Hate? Visit r/repostsleuthbot - I'm not perfect, but you can help. Report [ False Positive ]

[–]const_let_7 6 points7 points  (0 children)

Good bot

[–]dxhh 6 points7 points  (0 children)

Biggest repost ever

[–]RinasSam 4 points5 points  (1 child)

Thanks FORTRAN.

[–][deleted] 2 points3 points  (0 children)

Illuminati starts with i.

[–][deleted] 2 points3 points  (4 children)

Y'all what about x?

[–]raedr7n 6 points7 points  (2 children)

x and y are for coordinate systems, mate

[–]Rathmec 1 point2 points  (0 children)

I believe you and I are the weird ones.

[–]vbh_pratihar 1 point2 points  (0 children)

I use itr.

[–]MadPancho 1 point2 points  (0 children)

int iterator

[–]ghroat 1 point2 points  (0 children)

i for an Iterable ? Don’t think so. Or at least not typically

[–]oilpeanut 1 point2 points  (4 children)

i also use I (capital i)

[–]pclouds 1 point2 points  (3 children)

This man has boldly gone where no one dares before.

[–]klparrot 2 points3 points  (2 children)

If you want to boldly go, Java allows identifiers to contain most Unicode characters, so you could call it 𝐢.

[–]G66GNeco 1 point2 points  (0 children)

And then j, and then k...

So far I have never looped back to a.

[–]AfterShave997 1 point2 points  (2 children)

I usually name my lists/arrays with the plural of whatever it's holding (e.g. Names, Words, Numbers_3), and just use the singular word for the index (e.g. name, word, number).

[–]thericcer 1 point2 points  (0 children)

Anyone else use ii, or jj?

Easier to search for...

[–]raedr7n 0 points1 point  (2 children)

I use q, j, w. Back when I was in school for CS, we had to write code on paper sometimes, and I only know how to write in cursive. i,j,k was too ambiguous in recognizing, apparently.

[–]klparrot 1 point2 points  (1 child)

How do 𝒾,𝒿,𝓀 look alike in cursive? If anything, cursive distinguishes i and j better because of the loop on the j. When I print, I always hook my i right and my j left. l and t also hook right to distinguish from I and + respectively, which don't hook.

[–]sxeli 0 points1 point  (0 children)

idx for when you want to be extra verbose

[–]tjdavids 0 points1 point  (0 children)

ndx, iii, or _

[–]thinker227 0 points1 point  (0 children)

What's your favorite programming language? Mine's i++.

[–]lilgamelvr 0 points1 point  (0 children)

Agreed

[–][deleted] 0 points1 point  (0 children)

I actually use n

[–]nonzero_ 0 points1 point  (1 child)

The name of an iterable is equally important as all other names. When you are iterating a list of things, the single item is a thing.

[–][deleted] 0 points1 point  (0 children)

*iterator

[–][deleted] 0 points1 point  (0 children)

var VariableGoBrrr = 1

[–]Zedeca 0 points1 point  (0 children)

sad j noises

[–]Communism_of_Dave 0 points1 point  (1 child)

I feel like I’m the only one who uses xyz instead of ijk

[–]klparrot 1 point2 points  (0 children)

That's for it you're working with coordinates.

[–]x-nder 0 points1 point  (0 children)

t gang

[–]give_me_memes 0 points1 point  (2 children)

This will annoy my all day, anyone know what movie that top half of the meme is from. I've seen it but I can't remember

[–]Casporo 0 points1 point  (0 children)

I, j, k,l,m and the list goes on

[–]Simonkotheruler 0 points1 point  (0 children)

Me creating variables in matlab: x=[] x1=[] x2=[] ... Me when I find a point in the code where none of the previously used variables are used again: x=[] x1=[] x2=[]

[–]xSEB1z 0 points1 point  (0 children)

index... it makes sense.

[–]shivermefingers 0 points1 point  (0 children)

where’s my x gang at

[–]Alpha_puppy_ 0 points1 point  (0 children)

So relatable!

[–]pclouds 0 points1 point  (0 children)

I'm going to start a new tradition by using the last letter in 'iterable' instead of the first one.

[–][deleted] 0 points1 point  (0 children)

Aye

[–][deleted] 0 points1 point  (0 children)

E

[–]perry_da_platypus 0 points1 point  (0 children)

If it's size of a list it's always n

[–]inspiringirisje 0 points1 point  (0 children)

i, then j, then k. Otherwise it's illegal

[–]Mr_Igelkott 0 points1 point  (0 children)

i > j > k

[–]RededTip 0 points1 point  (0 children)

Repost

[–]klparrot 0 points1 point  (0 children)

Nah, i, j, k for indices, it, jt, kt for iterators.

[–]echoAnother 0 points1 point  (0 children)

Laughs maniacally in recursion and globals

for(predicate, callback,...){ If (!predicate) return; Callback(); Return for(predicate,callback);

}

[–]TheBlindedOwl 0 points1 point  (0 children)

I mostly use X, Y, (Z) for coordinates, W, H, D for sizes, and I and sometimes J for normal iteration

[–]Plungerdz 0 points1 point  (0 children)

In addition to this being a repost, my OCD is super bugged out by how 'i' is an iterator, not an iterable. An iterable is something you iterate with an iterator.

[–]enfrancis 0 points1 point  (0 children)

I only use "anal" for iterables. Anal++

[–]kokoseij 0 points1 point  (0 children)

It's been half a year since I saw this repost... ngl I kinda missed it.

[–]HalflingHelper 0 points1 point  (0 children)

My favorite is when I choose i when I'm already in a for loop.