Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Isn't it better to avoid repetitive looping?

    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?
    *this message will self destruct in n-seconds*

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •