LoginLogin

Why is I so commonly used for FOR loops?

Root / Programming Questions / [.]

IAmRalseiCreated:
What I mean is when someone wants a FOR loop to loop 5 times, 99 times out of 100, They'll make their code look like this:
FOR I=1 TO 5
 [code goes here]
NEXT
When in reality, the value doesn't have to be I, so it could also be written like this:
FOR CATS=1 TO 5
 [code goes here]
NEXT
This is just really strange.

I stands for Iteration so it only makes sense to use it, and its usually not used as anything else for consistency, but theres nothing stopping you from using it.

I stands for Iteration so it only makes sense to use it, and its usually not used as anything else for consistency, but theres nothing stopping you from using it.
Oh. That makes sense.

If you try to use actual names it usually gets annoying For example:
DIM NAMES$[10]
FOR NAME=0 TO 10-1
 PRINT NAMES$[NAME]
 IF NAME == "John" THEN ... 'oops
NEXT
It's easy to make mistakes where you accidentally use the index variable instead of the value.

If you try to use actual names it usually gets annoying For example:
DIM NAMES$[10]
FOR NAME=0 TO 10-1
 PRINT NAMES$[NAME]
 IF NAME == "John" THEN ... 'oops
NEXT
It's easy to make mistakes where you accidentally use the index variable instead of the value.
Okay, and please close this

other reasons: there was once a time when dinosaur languages existed where only a few characters were significant in variable names. some of those languages had particular letters used for implicit typing. most of computer science comes from mathematics, where single-character identifiers are the norm.

Okay, and please close this
Why do you always seem so keen to close a thread? I’ve noticed you like to make a thread and then tell an admin to just close it after three people make a comment.

Okay, and please close this
Why do you always seem so keen to close a thread? I’ve noticed you like to make a thread and then tell an admin to just close it after three people make a comment.
Because there's no reason to keep a thread open after the question was answered.

Okay, and please close this
Why do you always seem so keen to close a thread? I’ve noticed you like to make a thread and then tell an admin to just close it after three people make a comment.
Because there's no reason to keep a thread open after the question was answered.
Yes there is. Other people might have the same question, and may have additional questions on this subject. Why stifle future conversation before it starts?

I see the same notation used in mathematics a lot, like vector calculus and linear algebra, i, j, and k are used as well. Such as, if you have a matrix X, you might represent a single element in the matrix as xij where i is your row and j is your column. If you are looping through a matrix, you can also use that same notation.
DIM X[10,10]
FOR I = 0 TO 9
  FOR J = 0 TO 9
    PRINT X[i,j]
  NEXT
NEXT

*Why am I so commonly used for FOR loops?

*Why am I so commonly used for FOR loops?
lol