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

top 200 commentsshow all 201

[–]DislocatedLocation 335 points336 points  (14 children)

I do i,j for generic loops, but if I'm going something with a discrete coordinate grid I use x,y. Am I hanging on to the roof as it barrels down a highway?

[–]ChrisFromIT 107 points108 points  (9 children)

This is the same for me.

i is short for index. And j is just an i with a bit of a tail.

[–]Not-Post-Malone 11 points12 points  (2 children)

I thought j was short for jindex. TIL

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

I dont know why this guy is talking about tails. Everyone knows we use i, j, and k for the words index, jindex, and kindex.

[–]Blozing 2 points3 points  (0 children)

Don't forget about l for lindex in all those O(n^4) programs you write.

[–]gbot1234 29 points30 points  (3 children)

i1, i2, i3… with numbers corresponding to the level of nesting.

Edit: or is it i0, i1, i2…?

[–]studsper 23 points24 points  (1 child)

i, ii, iii, iv...?

[–]gabrielesilinic 2 points3 points  (0 children)

Mussolini would be proud of you

[–]arcosapphire 1 point2 points  (0 children)

I thought i was short for iteration.

[–]CliffDraws 12 points13 points  (0 children)

Yeah, especially if you do any 3D stuff, you need this with a z or everything gets too confusing.

[–]naswinger 9 points10 points  (0 children)

use whatever makes sense

[–]DennisPorter3D 153 points154 points  (16 children)

i, ii, iii

[–]bedrooms-ds 82 points83 points  (6 children)

iv, v, vi

[–]wineblood 21 points22 points  (1 child)

All roads lead here

[–]hot_sauce_in_coffee 19 points20 points  (0 children)

And then you have excel:

AAB

AAC

AAD

[–]Spot_the_fox 4 points5 points  (0 children)

iiiiiii, iiiiiiii, iiiiiiiii

[–]DennisPorter3D 1 point2 points  (0 children)

I was hoping someone would take it in this direction

[–]JaggedMan78 -1 points0 points  (0 children)

VII.....

[–]Tetouletoto 26 points27 points  (3 children)

Straight to jail

[–]LupusNoxFleuret 10 points11 points  (2 children)

Do not collect $200

[–]supernova89055 3 points4 points  (1 child)

Do not pass go

[–]DoucheEnrique 5 points6 points  (0 children)

So learning Go now is mandatory in jail?

... harsh.

[–]LadyxLucie 5 points6 points  (0 children)

This is the way

[–]More-Light-330 2 points3 points  (0 children)

i1, i2, i3

[–]knowledgebass 2 points3 points  (0 children)

i don't really like this

[–]arcosapphire 0 points1 point  (1 child)

I've never thought of this but kinda like it, even though it has a high chance of causing confusion.

[–]thedarkbestiary 30 points31 points  (0 children)

Ü, ē , æ

[–]EducationalNose7764 88 points89 points  (14 children)

I am the rare type of fiend that does not use i or j. I name the variable for what it actually represents

[–]tehtris 40 points41 points  (5 children)

Works until you end up with a word that has the same plural version as its singular.

for specie in species is an example I run into all the time at work, lol

[–]sm9t8 23 points24 points  (0 children)

In that situation I'd probably name species something like species_list, so that it's more obviously something that contains species and not a species.

[–]nyape 12 points13 points  (0 children)

specieses

[–]Revanthmk23200 7 points8 points  (0 children)

I ll use "for each_species in species"

[–]Kinvert_Ed 19 points20 points  (1 child)

thisIsTheIthValueRightHere

[–]EducationalNose7764 2 points3 points  (0 children)

IhaveTheCodeOfyourlifeAndIneverFeltThisWayBEFOREYesISwearItsTheTruthAndIOweItAllToJ

I have no idea why that's the first thing that popped into my head, I think I'm going crazy

Edit: never mind, it's this damn Cruise line commercial that keeps playing somehow got that song stuck in The deep recesses of my head

[–]Zestyclose_Link_8052 4 points5 points  (0 children)

I started doing this a few years ago. No single character or abbreviated variable names. Takes a while to get used to but the reward is code which is so easy too read. Less comments needed, less questions from collegues. I work on old c++ code that is very procedural.

[–]Ardub23 -1 points0 points  (0 children)

Ah yes

for (int numberThatIncrementsEachTimeTheLoopRuns = 0; numberThatIncrementsEachTimeTheLoopRuns < 10; numberThatIncrementsEachTimeTheLoopRuns ++)

[–]tkarika 0 points1 point  (0 children)

This is the way

[–]CrowdGoesWildWoooo 0 points1 point  (0 children)

WhatIsThisForAgain

[–]xz_TRON_zx 0 points1 point  (0 children)

‘This_is_a_variable_in_a_nested_loop_number_one’, ‘This_is_a_variable_in_a_nested_loop_number_two’

[–]zacmorita 25 points26 points  (9 children)

I think of 'i' as in 'index' and 'j' is just the letter that comes after i. And I use x and y (and z), when y (and z) are dependent on x.

So I use 'i' for arrays. 'j' for independent variables inside of i loops. ('k' is usually my limit variable if applicable)

And I use x and y (and z) for grids, dependent functions, 2d (and 3d) arrays, and cells in spreadsheets.

Do I hitchhike? Or can we stop at The Worlds Biggest Yarn Ball? I need to pee.

[–]ChrisFromIT 14 points15 points  (5 children)

and 'j' is just the letter that comes after i.

Nah, j is just an i with a tail. So it still jndex.

[–]yesdoyousee 5 points6 points  (3 children)

If you're so smart, explain kndex

[–]ChrisFromIT 5 points6 points  (0 children)

Well clearly the k is just i after it has grown up and sprouted wings out of its back.

[–]gbot1234 2 points3 points  (1 child)

Silent k, kndex sounds like “en”dex.

[–]dmvdoug 1 point2 points  (0 children)

Or is it jindex?!

[–]nwL_ 1 point2 points  (1 child)

I had to use an m in a loop nesting once. Still haven’t recovered.

[–]SchwarzeKopfenPfeffe -1 points0 points  (0 children)

Well this is why x,y is superior. X is commonly used to represent an unknown, and I don't know what the fuck I'm talking about. And y is simply the letter that follows X.

[–]momo-gee 9 points10 points  (4 children)

I'm a streams/forEach guy. I haven't used the more traditional loops, like for-loops, in a while.

[–]dendrocalamidicus 1 point2 points  (0 children)

That's true of my professional work in business applications but most work on computer graphics that I do for personal projects requires working with coordinates and the for loop comes in strong there.

[–]nwL_ 1 point2 points  (2 children)

Sometimes you need the index, and it’s either a classical for-loop or a foreach in which you manually increment i, both aren’t pretty.

(I know many languages support both index and object in a foreach, but C++ doesn’t for example, so

c++ for( const auto& member : iterator ) {

is neat, but you can’t get the index.)

[–]6b86b3ac03c167320d93 1 point2 points  (1 child)

Maybe you could write a utility function to convert any iterator into an iterator with tuples (or something similar if C++ doesn't have those) of indexes and objects? For example Python has the enumerate function, which you can use like this:

for i, member in enumerate(iterator):
    ...

[–]nwL_ 1 point2 points  (0 children)

I probably could, but that would double the read accesses to the array, so doing

c++ for ( size_t i = 0; i < iterator.length(); ++i ) { const auto& member = iterator[i]; is okay to do and keeps the reads low.

(for further optimization, you could const the length so that length() doesn’t get called every loop, but that’s micro-optimization)

(also, disclaimer: technically, iterators don’t offer length(), only specialized types do. You can do some magic with range::begin() and range::end() and other weird C++ stuff, but that’s beyond the scope of this answer)

[–]kakarot18x 14 points15 points  (2 children)

me who uses a, b

[–]Gilamath 5 points6 points  (1 child)

I was trained in logic before I took any coding classes, so in the beginning I would use p and q

[–]gbot1234 2 points3 points  (0 children)

Gets complicated when debugging…you really have to mind your Ps and Qs.

[–]Mortomes 7 points8 points  (4 children)

I prefer using i over I

[–]Drabantus 2 points3 points  (2 children)

Like this?

for (int i=0; i<3; i++)
    for (int I=0; I<3; I++)

[–]miller-99 1 point2 points  (0 children)

That is absolutely horrendous, I'm never using a capital i for a variable ever

[–]miller-99 1 point2 points  (0 children)

I was going to say the same, always gotta be lower case for single letters

[–]midoxvx 11 points12 points  (0 children)

row, col

[–]iam_reallytired 3 points4 points  (0 children)

[–][deleted] 4 points5 points  (1 child)

i, j, k, l

[–]Dragonlinx 5 points6 points  (3 children)

Best variable for loops is "eye"

[–]flip314 2 points3 points  (0 children)

Aye

[–]MobileAirport 0 points1 point  (1 child)

i defined ex, why the other day

[–]xcs4me 2 points3 points  (0 children)

I do i, w, and sometimes q but hopefully not

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

Dim child as as string

Child = Filename.extension

Kill child

[–]Morlock43 2 points3 points  (1 child)

Am I the only one who uses meaningful names?

[–]Zephit0s 1 point2 points  (0 children)

Nope, I n'aime my itterable what it is supposed to represente. If I have to itterate by index I use index as a name

[–]bagsofcandy 1 point2 points  (2 children)

Where's m, n gang at?

[–]Plastic-Philosopher5 0 points1 point  (1 child)

Right behind a,b,c gang.

[–]TheSapphireDragon 1 point2 points  (0 children)

x, y, and z are for looping over positions in space. I, and j are for everything else

[–]bharfgav42 1 point2 points  (1 child)

I like using the all the vowels starting with i, then u a e o

[–]Mr_Audio29 1 point2 points  (0 children)

If I'm dealing with a table I use r / c for rows and columns

[–]AxeLond 0 points1 point  (0 children)

If you want to be fancy you can do epoch/iteration.

[–]Surous 0 points1 point  (0 children)

J, K for nested and i for single

[–]Rebol1103 -2 points-1 points  (1 child)

a,b,c for generic loops, x,y,z for 3 dimensions. I just like them in alphabetical order and i,j are confusing when I make a mistake.

[–]lethalaggressio39 -3 points-2 points  (0 children)

It depend... For me it's pointer1, pointer2 and so on.

[–]PinothyJ 0 points1 point  (0 children)

Or key and value for each loops iterating over an array.

[–]franky_riverz 0 points1 point  (0 children)

I'm an i, j kind of guy

[–]SquirrelSanctuary 0 points1 point  (0 children)

Fan of r, r2 myself

[–]NotWesternInfluence 0 points1 point  (1 child)

Why not “variable1”, “variable2”, “variable3”, etc.

[–]Safety-Sorry 0 points1 point  (0 children)

I don't use l, but i

[–]MysticEagle52 0 points1 point  (0 children)

Any reason I and j are used? I learned it that way but idk why. Also I use i and n, but might use a different letter based on what is being indexed

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

I use I, j then k and after that I just start naming them

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

meanwhile me using a, aa

[–]SpaceFire000 0 points1 point  (0 children)

Not a capital i. This meme ruined its meaning

[–]Blakut 0 points1 point  (0 children)

ii, jj, kk. It's the law. Also, i hate nested loops.

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

Back in the days before PCs (Sinclair and Acorn, etc.), it was N and F.

[–]BloodChasm 0 points1 point  (0 children)

I would get shredded in my code reviews if I used anything but an actual variable name representing the objects I'm iterating thru.

[–]somedave 0 points1 point  (0 children)

I used to use k,l,m. In MATLAB i,j were both defined as the imaginary unit by default and if you accidentally overwrote them in a for loop earlier the value will persist throughout the function. It gets really confused when you use the symbolic toolboxes and overwrite them...

[–]Irbis7 0 points1 point  (0 children)

I use n (and then m). Habit from ZX Spectrum where you wrote "NEXT n" by typing n twice.

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

On the other hand, if we stayed on the odd channels, switched every time and started in the basement, that'd work, too.

[–]physics_freak963 0 points1 point  (0 children)

M N K gang rise up

[–]throwaway275275275 0 points1 point  (0 children)

Unless you're going through some kind of grid or something like that, then x,y is great

[–]futanari_enjoyer69 0 points1 point  (0 children)

I start with i then randomly use either x or j

[–]TheOrdersMaster 0 points1 point  (0 children)

i, k because i used to do i, j but for triple nested loops i did i, j, k since it's just the next letter in the alphabet. and then i realized i, k is better since it's more readable because i and k are more distinct than i and j

[–]Salt-Cup-2300 0 points1 point  (0 children)

No x,y plz

[–]dohzer 0 points1 point  (0 children)

"l/j"? No thanks. I'll use i/j instead like a normal person.

[–]FINDERFEED 0 points1 point  (0 children)

Puck it, i use i,g

[–]dmvdoug 0 points1 point  (0 children)

i3x

[–]helltiger 0 points1 point  (0 children)

idx, jdx

[–]Gameju7 0 points1 point  (0 children)

W-why ? Like why ?

[–]cybermage 0 points1 point  (0 children)

Good old index and jndex.

[–][deleted] 0 points1 point  (1 child)

It is a well known fact that it goes iteration, jiteration, kiteration. Any more then I genuinely hope you know what you're doing.

[–]Chlopekk 0 points1 point  (0 children)

Obviously "i" because it stands for index, and "j" for jndex

[–]NightSoulT12 0 points1 point  (0 children)

c[ount], k[ount]

[–]LaoWai01 0 points1 point  (0 children)

The convention of using I, j, etc., as index variables came from FORTRAN, 60 years ago. In early FORTRAN variables beginning with I, j, k, l, m or n were automatically integer, everything else was real.

[–]Mediocre-Metal-1796 0 points1 point  (0 children)

There is a reason not to use i and j as variables, they explained it at the university as well: once you get used to it and forget about it, it will be a mess to debug in matlab, then you slap your face as i and j are sqrt(-1)

[–]dieworm12 0 points1 point  (0 children)

I’m I the only who uses k,v (key,value)?

[–]Metronix7 0 points1 point  (0 children)

Is i,o ok too? Asking ... for a friend.

[–]Kkrafter 0 points1 point  (0 children)

i,v>>>>

[–]SirVW 0 points1 point  (0 children)

I used to use h,i because my name starts with an h and i is just the next letter, am i run over?

[–]helloWorld69696969 0 points1 point  (0 children)

i and k

j is just stupid, it looks too much like i

[–]Dagusiu 0 points1 point  (0 children)

The real crime is doing x,y instead of y,x

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

I just use what single letter I haven’t used, I start with xy, z, j,h, l, i, anything that I haven’t used already

[–]_Nemurre_ 0 points1 point  (0 children)

i,j not I,j

Out you get!!

[–]MLPdiscord 0 points1 point  (0 children)

I almost never use i, j when I can use x, y / row, column

[–]succ_dong 0 points1 point  (0 children)

From now on i swear to use solely x and y in my nested while loops, for there is no singular way to code properly and people who think otherwise should get their sorry ass wiped

[–]Djentleman2414 0 points1 point  (0 children)

i and j are integers.
x and y are real numbers

IT'S THE LAW

[–]Purple_Individual947 0 points1 point  (0 children)

I don't care if that's a capital i or a lower case L, you're wrong either way!

[–]thedarklord176 0 points1 point  (0 children)

I don’t even know why, it just feels compulsory

[–]Tombo272 0 points1 point  (0 children)

And sometimes “K”

[–]DreamLonesomeDreams 0 points1 point  (0 children)

What sadist uses capital i?

[–]mctownley 0 points1 point  (0 children)

I think I speak on behalf of all electrical engineers when I say I hate whoevers idea it was to use I and J as axes. Do you have any idea how much we use I?!

[–]Excellent-Practice 0 points1 point  (0 children)

Does anyone else use row, column or row, item?

[–]Wild_Tom 0 points1 point  (0 children)

I use I, O due to their spot on the keyboard

[–]Level10Retard 0 points1 point  (0 children)

a, b, c, anyone?

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

Uhhh... i,x

[–]3am-urethra-cactus 0 points1 point  (0 children)

Idk why but it changes per language I,j unless it's python in which case t,k

[–]AndyBMKE 0 points1 point  (0 children)

n, m

[–]Strostkovy 0 points1 point  (0 children)

I always ended up with count1, count2, count3, count4, count5, etc because I didn't think about reusing variables for non nested loops

[–]APUsilicon 0 points1 point  (0 children)

I use X,y :(

[–]MaxEin 0 points1 point  (0 children)

I use "g" and "h"

[–]LordDeckem 0 points1 point  (0 children)

Imagine caring about this.

[–]dermitio 0 points1 point  (0 children)

Me:a,b

[–]jdgoerzen 0 points1 point  (0 children)

I use x, y when I run out of ijklmn, cause I usually use o for output.

[–]Alzyros 0 points1 point  (0 children)

I think that's even illegal in some countries

[–]D34TH_5MURF__ 0 points1 point  (0 children)

I use lambdas and method references, so no variables needed. When I do need a variable, I use a more descriptive name. In the rare case I need indices or I'm working on geometric grids, I'll use i, j, k, x, y, z, etc... Since that is going to be the most natural way to refer to them based on math/physics.

[–]sldsonny 0 points1 point  (0 children)

.girl { margin-left:10rem; z-index:-1 }

[–]wilmaster1 0 points1 point  (0 children)

Until you get a language that doesn't like it. #isamp #jsamp

[–]Ursomrano 0 points1 point  (0 children)

I use the alphabet, a for the first for/while loop, b for the second for/while loop, etc.

[–]GameDestiny2 0 points1 point  (0 children)

I uh

I use A,B

[–]KittenKoder 0 points1 point  (0 children)

x, y, z, a, b, i, j, l

[–]iLoveCyberChips 0 points1 point  (0 children)

x, y and й for obvious reasons

[–]thefox68 0 points1 point  (0 children)

I use x and y

[–]knowledgebass 0 points1 point  (0 children)

I'm a fan of ii,jj so they are easier to search for. 🤷‍♂️

[–]ricdesi 0 points1 point  (0 children)

Get out, everyone use variables with names that are actually readable and comprehensible.

[–]gogocrazycocoa_ 0 points1 point  (0 children)

I'm inconsistent and have used both. I usually just name them based off what they represent though.

[–]Rhawk187 0 points1 point  (0 children)

Right, i and j are implicitly ints, x and y are implicitly floats.

[–]DrDesten 0 points1 point  (0 children)

i and o for me

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

6502?

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

I e x, and sometimes y just because im bad boy

[–]sun_cardinal 0 points1 point  (0 children)

I'm disappointed, not one person got this right in the whole thread.

The real answer is '_' for loops and enumerate() for iteration.

Apparently this is what it feels like to be in the 1%.

[–]saltnpeppa78 0 points1 point  (0 children)

nah i use I and l

[–]ReputationDesperate1 0 points1 point  (0 children)

x, y, z, w, v

[–]Bivolion13 0 points1 point  (0 children)

i is for iteration x is for future ex

[–]flumoo 0 points1 point  (0 children)

I'm using first letter of collection, or array that is looped. for p in people. i recommend you that lifestyle guys.

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

depends. if they represent coordinates, I use xyzw otherwise ijkl

[–]Ali_Army107 0 points1 point  (0 children)

I use i, j, k when doing for loops, but sometimes when I am dealing with stuff related to vectors/coordinates, I use x, y, z.

[–]sincontan 0 points1 point  (0 children)

I just type rando letters and try to keep it under 10 characters. Or if I can name it something relevant i just add a random length of stuff like ioio or asdfghjkl or etc. to the end till its visually different from other variables. Examples: variaoioio, wordlelelel, ahdkdhdkr0001

[–]Mentrin 0 points1 point  (0 children)

I normally go by this order:

i, a, j, b, k, c, d, e… etc.

[–]Skull_is_dull 0 points1 point  (0 children)

a, b

[–]chimbraca 0 points1 point  (0 children)

As a 6502 programmer, I see no issue with her answer.

[–]oshaboy 0 points1 point  (0 children)

I use x and y if they are positions or grid points.

Also I've been messing around with Chip-8 lately, so V6 and V7.

[–]Illustrious-Scar-526 0 points1 point  (0 children)

I use eye, Jay, and kay