Results 1 to 15 of 15

Thread: [RESOLVED] [2005] Skip to Next in 'For Each' loop?

Hybrid View

  1. #1
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [2005] Skip to Next in 'For Each' loop?

    Quote Originally Posted by penagate
    Code can be as elegant as you make it.

    Plan the logic flow before you start bashing the keyboard like the thousand proverbial monkeys, and unlike them you might have a chance of creating a work of Shakespeare

    Edit:
    Well, let's see:
    - Try/Catch is a goto
    - Return is a goto
    - Exit Sub is a goto
    - Continue is a goto

    Good luck with all those "If valid", "If Not Complete", "If ..." nestings. If your methods are about 5 lines long on average you can do it, but otherwise these goto's clarify the code rather than obscuring it.
    Last edited by David Anton; Jul 16th, 2006 at 09:28 AM.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Skip to Next in 'For Each' loop?

    Quote Originally Posted by David Anton View Post
    Well, let's see:
    - Try/Catch is a goto
    - Return is a goto
    - Exit Sub is a goto
    - Continue is a goto

    Good luck with all those "If valid", "If Not Complete", "If ..." nestings. If your methods are about 5 lines long on average you can do it, but otherwise these goto's clarify the code rather than obscuring it.
    While that is to true to an extent, I don't think that it's really the same thing. I wouldn't really consider Try...Catch to be the same at all and all the others have a well-defined destination, i.e. either the end of the current loop or method or the beginning of the current loop. It's very easy to follow each of them because you know exactly where you'll end up. GoTo, on the other hand, can end up basically anywhere. When you reach a GoTo you have no idea whether you will be jumping forward or back and the destination could be nested pretty much at any level.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    710

    Re: [RESOLVED] [2005] Skip to Next in 'For Each' loop?

    I was exaggerating somewhat (way back then), but I still think that if you avoid all structured 'jumps' (Continue For, Exit For, etc.) that you end up with something far worse than what you're trying to avoid. That is, you end up with incredibly nested if/else blocks that has no more elegance than an unnested sequence with a couple of Continue's or Exit's thrown in.

    This is also related to the old 'single exit point' rule for methods - it leads to code that is messier and harder to follow.
    David Anton
    Convert between VB, C#, C++, & Java
    www.tangiblesoftwaresolutions.com

Posting Permissions

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



Click Here to Expand Forum to Full Width