This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

array adding int.

I'm trying to fill an array with a rotating counts then add the all up each time the sub is called. When I simulate this code I never see the i++ index. I guess keil supports i++ by itself.

i++;

if(i == 10){i == 0;}

array[i] = data;

data = 0;

for (a = 0; a < 10 ; a++)
	{data = data + array[i];}

Parents
  • for (a = 0; a < 10 ; a++)
    	{data = data + array[i];}
    "I understand what you're doing here, but adding up all of the array contents..."

    That might be what he's trying to do, but it's not what that piece of code does, is it?

    The loop uses 'a' to repeat the statement
    data = data + array[i];
    ten times.
    'i' does not change during the loop!
    Therefore, each time around the loop, it adds the same element from the array!

Reply
  • for (a = 0; a < 10 ; a++)
    	{data = data + array[i];}
    "I understand what you're doing here, but adding up all of the array contents..."

    That might be what he's trying to do, but it's not what that piece of code does, is it?

    The loop uses 'a' to repeat the statement
    data = data + array[i];
    ten times.
    'i' does not change during the loop!
    Therefore, each time around the loop, it adds the same element from the array!

Children
No data