+ 3
Why is i and j used in for loops?
10 Answers
+ 7
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)
+ 5
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.
+ 2
i for index or integer
+ 2
They are just name of variables you can choose whatever you wantđ
+ 2
I-short of word - iteration , j-next short simbol in alfabet after i
+ 2
I'm new in here limit help me learn
+ 2
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
+ 2
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.
+ 2
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.
+ 2
I would say because i and j are used commonly as indices in Linear Algebra.