Hey, welcome to ZBCode, the premier coding forum for ZB. Here you fill find some of the best Invisionfree and Zetaboards Codes on the network! Unfortunately, you're sorta hovering around in guest mode at the moment; why not join in on the fun? Register an account and you can start accessing the wealth of resources we have available here. Enjoy your stay at ZBCode, and remember to tell all your friends about us; the more members, the more codes available. ![]() Interested in joining? Click here. If you are already a member of ZBCode, feel free to login right here: |
- Pages:
- 1
- 2
| Coding For Loops | |
|---|---|
| Tweet Topic Started: Aug 15 2008, 07:24 AM (911 Views) | |
| Webworldx | Aug 15 2008, 07:24 AM Post #1 |
![]()
|
Hi folks, Just thought I'd throw in a quick one for all of you not converting to writing Javascript through libraries yet. Take a look at: http://www.openjs.com/articles/for_loop.php I see a lot of people using something like:
.. i've been guilty of it myself previously, but think about the number of extra lookups going through the iterations - especially on say a TD or a DIV, or a SPAN.. that's 100's of elements per page. Improve you efficiency
|
|
ZetaBoards Codes Index - 700+ ZB Codes InvisionFree Codes Index - 6000+ Codes and Skins | |
![]() |
|
| Ryura | Aug 15 2008, 08:06 AM Post #2 |
![]()
|
This *still* isn't the fastest way. For loops in general should be completely forgotten, actually - while loops are much faster. This isn't actually necessary until you're looping arrays, specifically DOM compilations, with thousands of elements.
Edited by Ryura, Aug 16 2008, 10:06 AM.
|
![]() |
|
| Webworldx | Aug 15 2008, 09:45 AM Post #3 |
![]()
|
Reverse while loops are indeed a good deal faster again, so a:
Might speed up your code even more. |
|
ZetaBoards Codes Index - 700+ ZB Codes InvisionFree Codes Index - 6000+ Codes and Skins | |
![]() |
|
| HolySavior | Aug 15 2008, 10:13 AM Post #4 |
![]()
Modifying The World Around You
![]()
|
nice. i like it. good find and thanks for posting that! |
![]() |
|
| Godkillah | Aug 15 2008, 10:32 AM Post #5 |
![]()
|
as a while loop can do all a for loop can and even more for loops could easily be left out. they just look so secksi |
|
http://www.pdforums.net For good and fast support on all your coding, graphics or skinning needs! | |
![]() |
|
| slayer766 | Aug 15 2008, 11:36 AM Post #6 |
![]()
Hello all
![]()
|
Yeah they do, and wow I never even thought of doing a for loop like this... |
![]() |
|
| Ryura | Aug 15 2008, 03:58 PM Post #7 |
![]()
|
I'm *pretty* sure mine's still faster.I did a lot of research as well as my own testing a while back that lead me to my do...while loops. Pre-decrementing is basically always faster than post (--i instead of i--). Obviously, even on huge arrays the difference between our methods is very low. After getting into decrementing a while or do..while loop, the only noticable speed increase you can make is to implement Duff's Device. Edited by Ryura, Aug 15 2008, 04:24 PM.
|
![]() |
|
| Webworldx | Aug 16 2008, 04:32 AM Post #8 |
![]()
|
It will, but pre-dec only checks above zero, so the first element of the array gets missed.
Edited by Webworldx, Aug 16 2008, 04:33 AM.
|
|
ZetaBoards Codes Index - 700+ ZB Codes InvisionFree Codes Index - 6000+ Codes and Skins | |
![]() |
|
| Ryura | Aug 16 2008, 10:05 AM Post #9 |
![]()
|
Not in my loop. Try this example:
|
![]() |
|
| Zefer | Aug 21 2008, 09:30 AM Post #10 |
![]()
|
That's how I do it. |
![]() |
|
| 1 user reading this topic (1 Guest and 0 Anonymous) | |
| Go to Next Page | |
| « Previous Topic · Code University · Next Topic » |
- Pages:
- 1
- 2











Improve you efficiency





7:48 PM Jul 10