Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fixes second for loop to use var i instead of var j #1052

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants