Why is i and j used in for loops? | Sololearn: Learn to code for FREE!


Why is i and j used in for loops?

3/23/2021 10:59:04 AM

محمد الشاوش

10 Answers

New Answer


i and j are not mandatory... however, as they often hold indexes of an array, that's common to use i (wich could also mean 'iteration')... inner loops then receive usually next letters: j, k... other commonly variable names used in loops could be x (as frequently used in math variable, with y then z), or even v (when used in for...in/of loops, where the variable would better mean 'value', with t, u). by the way, you could use 'the_counter_of_my_loop' if you want so... but you must need to type that long name everywhere you use it ^^ usually it's advised to use meaningful names for variables/functions, but for loop counters are often used only inside the loop, so it's implicitly allowed to have very short names in these cases)


Every programming language have some sort of rules to follow. Fewer example including camel case naming conventions( java), in c# variable name should start with capital letters, four spaces for indentation in Python and many more. You're completely independent to do whatever you want, but not following this simple terms will make your code different from others, perhaps more complex to grasp. this are not rules but responsibility for a programmer. Generally the i in for loops stands for iterator, that's why most of programmers use i instead of other names.


i for index or integer


They are just name of variables you can choose whatever you want😊


I-short of word - iteration , j-next short simbol in alfabet after i


I'm new in here limit help me learn


Variables starting with I through Q were integer by default, the others were real. This meant that I was the first integer variable, and J the second, etc., so they fell towards use in loops


i and j are just a variable name, you can use any variable name like a, b, c,x, y or number, length etc. i, j, k is probably preferred because they are short so fast to write in codes & commonly used by codes or courses we commonly see, so we also start using them.


for my opinions a lot of leaners use them because they find them in many examples of loops while they are studyng fundamentals or introductions in programming and they grow with them . so its a tendency. These days i use 'a' and 'b' as variables name to make sure that students are not creaming.


I would say because i and j are used commonly as indices in Linear Algebra.