News for hackers. Stuff that matters.
Re:Annotated code: Circles bouncing off lines by ahoge on Monday February 09, 2015 @02:21AM (#9020052)
In case anyone wonders about that reverse-for loop in updateCircles():

Iterating over an array in reverse allows you to remove items in the same iteration (at the very end of the loop). If you delete an item, the items which follow are downshifted by one which means that their indices also change.

However, this isn't a problem if you iterate in reverse, because you already took care of those items in previous iterations. The item you'll handle next will stay where it is.

This also works nice with unordered lists (or "bags").

There are no comments on this comment yet.