0
Usage of letters in tutorials
Is there a reason why tutorials in general often use x for the variable pet and i or k for the loop part ? Maybe further down the road even other letters... Why is that ? Why not use for (x=0; x<5;x++) Thanks
2 Antworten
+ 2
The "i" is shorthand for "index", and j and k are just the letters after. That notation is borrowed from mathematics.
Also from maths we get "x,y,z" and "a,b,c" for variables and "n" or "k" for numbers. "x,y,z" because of coordinates, "a,b,c" because they're the first letters, and "n" for number. "k" I don't really know, maybe its a constant (Konstante)
"f,g,h" are common for functions.
"xs" for lists (the plural of "x") is also somewhat common but only in programming.
+ 3
Basically you can call them however you want, but if you want to read and understand code quickly, it helps if certain things are mostly the same.
When you want to give names to variables that are only used in your specific program, it makes sense to choose very telling ones.
On the other hand, if you just index yourself through an array like you do several times in every program, why not just say i (or j, k) to something that doesn't really mean that much?