|
-
Jul 16th, 2006, 09:24 AM
#1
Re: [2005] Skip to Next in 'For Each' loop?
 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.
-
Jun 18th, 2010, 08:10 AM
#2
Re: [2005] Skip to Next in 'For Each' loop?
 Originally Posted by David Anton
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.
-
Jun 18th, 2010, 08:52 AM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|