Skip to main content

Bug Tracker

Side navigation

#7686 closed enhancement (invalid)

Opened December 02, 2010 10:09PM UTC

Closed December 03, 2010 01:18AM UTC

For loop should be changed to while loop

Reported by: nick@nickcammarata.com Owned by: nick@nickcammarata.com
Priority: undecided Milestone: 1.6
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocked by: Blocking:
Description

Line 612 of core.js in $.each();

for ( ; i < length; ) { could be better written as

while ( i < length ) {

It is less confusing, and even faster in some browsers according to http://jsperf.com/loops-while-vs-for/7.

I have made the change here: https://github.com/ncammarata/jquery/commit/4c1f406ec829986c65ba40b9fb44548fe3ed88e8

First bug report, I hope I did this correctly.

Attachments (0)
Change History (2)

Changed December 02, 2010 11:13PM UTC by rwaldron comment:1

owner: → nick@nickcammarata.com
status: newpending

I'm getting almost identical results in Chrome.

Changed December 03, 2010 01:18AM UTC by snover comment:2

resolution: → invalid
status: pendingclosed

Thanks for the report, but this is not a valid enhancement. That jsperf test is invalid; you are failing to reset the iterator between tests. Properly resetting the iterator value between tests, such as in this test, shows that the two loop structures function identically.