in reply to Re^2: Is it safe to append to the array you are iterating over
in thread Is it safe to append to the array you are iterating over
The problem is that even if the logic in the loop body doesn't cause an infinite loop; you are at the very least also iterating over all the additional elements that you push for no good reason. You've just pushed those values; you presumably don't want them to cause further pushes.
Why do pointless extra work when it is so easily avoided?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Is it safe to append to the array you are iterating over
by DrWhy (Chaplain) on Mar 14, 2013 at 19:23 UTC | |
by BrowserUk (Patriarch) on Mar 15, 2013 at 04:00 UTC | |
by Anonymous Monk on Mar 15, 2013 at 14:15 UTC |