For Loop, Array Question

What exactly is going on with this for loop?

is this determining the amount of indices in the array?

and is it putting zero (0) into each index?

1
2
3
  // lets say SYMBOLS == 20
   for (int z = 0; z < SYMBOLS; z++)
		symbolcount[z] = 0;
Last edited on
Marth wrote:
is this determining the amount of indices in the array?
No, that value appears to be stored in SYMBOLS.
Marth wrote:
and is it putting zero (0) into each index?
Yes.
It doesn't determine the amount, it resets them all to 0.

// lets say SYMBOLS == 20

for (int z = 0; z < SYMBOLS; z++) means z starts at 0
if z < symbols (20) means as long as z less than SYMBOLS (20)
z++ mean then add 1 to z
So it counts from 0 to 20 using z as the counter variable.
{ starts a block of code
symbolcount[z] = 0; as the value of z increases from 0 to 19, this changes the value of the variable symbolcount[] to 0;
} ends the code block

It is the same as

symbolcount[0] =0;
symbolcount[1] =0;
symbolcount[2] =0;
symbolcount[3] =0;
symbolcount[4] =0;

and so on..

Last edited on
thanks for the help!
Topic archived. No new replies allowed.