Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Duplicate/nested for loop #1013

Closed
ronyeh opened this issue Jun 2, 2021 · 2 comments
Closed

Duplicate/nested for loop #1013

ronyeh opened this issue Jun 2, 2021 · 2 comments

Comments

@ronyeh
Copy link
Collaborator

ronyeh commented Jun 2, 2021

for (i = 0; i < nums.length; ++i) {
num = nums[i];
note = num.getNote();
for (i = 0; i < nums.length; ++i) {
num = nums[i];
note = num.getNote();

It's late and I'm seeing double. :-D

While working on my PR I ran across these lines which stood out to me and just look wrong.

I believe the outer for loop can just be removed, correct? Since they both iterate on index i, by the time the inner for loop finishes, the outer one will also finish.

@sschmidTU
Copy link
Contributor

yeah, looks like one of the loops can be removed, they do the same thing.
It definitely doesn't make sense to have nested loops on the same index variable (i).

@ronyeh
Copy link
Collaborator Author

ronyeh commented Jun 2, 2021

Thanks for the sanity check @sschmidTU . I added a PR with the fix: #1014

0xfe added a commit that referenced this issue Jun 5, 2021
Fix duplicated for loop: issue #1013
@ronyeh ronyeh closed this as completed Jun 5, 2021
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

No branches or pull requests

2 participants