Skip to content

Conversation

@jamesongamble
Copy link

The second for loop in this example script reinitializes the variable i. Weird looping bugs may arise later with bigger arrays. As such, I have set the second loop to start at var j.

Before:

screen shot 2015-02-19 at 4 49 01 pm

After:

screen shot 2015-02-19 at 4 48 42 pm

@6pac
Copy link

6pac commented Feb 20, 2015

Not sure I follow. While it is true that these i instances are in the same scope, and the second one strictly does not need to be declared, what can be the problem if it's initialised ?

The place this kind of thing might cause problems is in reentrant code using a parent scope variable, or where the var keyword is forgotten and a global i is declared, which can definitely be unexpectedly changed at random times elsewhere. This case is neither of those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants