# Some really simple code?

**URL:** <https://forum.kirupa.com/t/some-really-simple-code/7345>\
**Category:** Uncategorized\
**Created:** [October 29, 2002, 2:47am UTC](https://forum.kirupa.com/t/some-really-simple-code/7345 "2002-10-29T02:47:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nipp2002](https://avatars.discourse-cdn.com/v4/letter/n/e5b9ba/32.png) [@nipp2002](https://forum.kirupa.com/u/nipp2002)\
**Post date:** [October 29, 2002, 2:47am UTC](https://forum.kirupa.com/t/some-really-simple-code/7345/1 "2002-10-29T02:47:09Z")

</div>

for (var i = 0;i\<9;i++) {  
trace(“Starting Loop”);  
trace(i);  
a += i;  
trace(a);  
trace(“ending loop”);  
}

Ok I understand how i is being assigned but when I trace(a) after the 2nd loop it traces the number 3 and from there a is changed HOW exactly is it doing that? I dont understand!  
This is some code i was looking up in a book and i’m frustrated because I dont understand how the variable a is changing! :q: :q:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [October 29, 2002, 3:17am UTC](https://forum.kirupa.com/t/some-really-simple-code/7345/2 "2002-10-29T03:17:42Z")

</div>

Your “a” variable is += the i

There for you have 9 loops and all the while i is increasing by 1

i = 0,1,2,3,4,5,6,7,8

(i+i=i)  
(0+1=1, 1+1=2, 2+1=3, etc)

a = 0,1,3,6,10,15,21,28,36

(a+i=a)  
(0+0=0, 0+1=1, 1+2=3, 3+3=6, 6+4=10, 10+5=15, etc)
