トピック
Brad GamerZim

For I=0 to 7, I see this in alot of programs, so with the little [very little] I know, its a starting point for an arrey, how does it work exsactly and why is the arrey name usaly [I]?

1そうだね
プレイ済み
返信[1]
親投稿
Ed CPFace
FOR/NEXT loops have lots of uses, but they're often associated with arrays because they're a simple way to perform the same operation on every member of the set. Like so: FOR I=0 TO 7 A[I]=2 NEXT In the first line, the variable I is created and given the value 0. When the program reaches the NEXT, it adds 1 to I. If I isn't more than 7, it goes back up to the top and repeats the loop.
2そうだね
プレイ済み
返信[2]
親投稿
Ed CPFace
It's a very neat way of performing a set of instructions FOR every value of I from 0 TO 7. Why is it I? Since the variable often isn't important anywhere outside the loop, programmers just come up with some "throwaway" name for a variable that they're not going to use anywhere else. I stands for "iterator", and it's become sort of traditional for programmers to use it in FOR loops.
1そうだね
プレイ済み
返信[3]
親投稿
Ed CPFace
It's the same way generic algebra equations often use X for their variable if the person writing the equation doesn't have a good reason to call it something else.
1そうだね
プレイ済み
返信[4]
親投稿
Brad GamerZim
ok, so to see if i have this, I=0 to 7, makes 0, and when looped it adds +1 to the value, until the value reaches its max [7] (so its a counting trigger of sorts.
0そうだね
プレイ済み
返信[5]
親投稿
Ed CPFace
Exactly. :) If you want a very clear demonstration, run this program: FOR I=0 TO 7 PRINT I NEXT That'll show you how I changes as it loops and where it ends.
1そうだね
プレイ済み
返信[6]
親投稿
Hanzo rzsense
I recommend confirming finally stored value in i with the following codes. It must be 8. FOR I=0 TO 7 PRINT I NEXT I PRINT"Finally i is ",i
1そうだね
未プレイ
返信[7]
親投稿
Brad GamerZim
did this just fooling around with it, its dumb but I love the outcome. thanks for the help with starting to understand programing.
1そうだね
プレイ済み