View Full Version : Isn't it better to avoid repetitive looping?
08-27-2004, 07:21 AM
If you want to toggle properties on a group of elements, like changing the appearance of whatever one was clicked last, wouldn't looping through all of them every time the event fired be sort of excessive? I've seen it where a global variable referenced the last-clicked one, so you'd only be dealing with two elements at a time (instead of however many are in the group)... seems better... any reasons why not?
Go for it. Of course it's more efficient. It's just extra code that sometimes developers don't feel like writing, and for small-ish groups, the difference is negligible.
08-27-2004, 08:03 AM
Thanks for confirming that.
It might have been more specific to ask whether conditionals usually require less processing than loops, but I guess that might depend... will see if I can tell. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.