|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
I miss loopWhen I'm inside a do while loop sometimes it's necessary to jump out of
the loop using exit do. I'm also used to being able to jump back and begin the loop again. Not sure which language my memories are of but I think I just said loop somewhere inside the loop and it immediately jumped back to the start of the loop and began again. I can't seem to do that in .net. I this functionality available? "cj" <cj@nospam.nospam> wrote in message I think in VB.Net 2005, you have the Continue statement, but I'm not sure. news:ex3Rt36RGHA.1572@tk2msftngp13.phx.gbl... > When I'm inside a do while loop sometimes it's necessary to jump out of > the loop using exit do. I'm also used to being able to jump back and > begin the loop again. Not sure which language my memories are of but I > think I just said loop somewhere inside the loop and it immediately jumped > back to the start of the loop and began again. I can't seem to do that in > .net. I this functionality available? In C#, it's continue (if my memory serves correctly). HTH, Mythran Unfortunately I'm using VB.Net 2003 right now and continue doesn't
appear to do that in 2003. I believe continue does have that functionality in some language. Mythran wrote: Show quoteHide quote > > "cj" <cj@nospam.nospam> wrote in message > news:ex3Rt36RGHA.1572@tk2msftngp13.phx.gbl... >> When I'm inside a do while loop sometimes it's necessary to jump out >> of the loop using exit do. I'm also used to being able to jump back >> and begin the loop again. Not sure which language my memories are of >> but I think I just said loop somewhere inside the loop and it >> immediately jumped back to the start of the loop and began again. I >> can't seem to do that in .net. I this functionality available? > > I think in VB.Net 2005, you have the Continue statement, but I'm not > sure. In C#, it's continue (if my memory serves correctly). > > HTH, > Mythran > "cj" <cj@nospam.nospam> schrieb: You can still mimick the behavior of 'continue' using a named label and > Unfortunately I'm using VB.Net 2003 right now and continue doesn't appear > to do that in 2003. I believe continue does have that functionality in > some language. 'GoTo'... -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Whowa! Your sure to get blasted for that idea. I hope you aren't using
your real name. :) I just might do that though. Herfried K. Wagner [MVP] wrote: Show quoteHide quote > "cj" <cj@nospam.nospam> schrieb: >> Unfortunately I'm using VB.Net 2003 right now and continue doesn't >> appear to do that in 2003. I believe continue does have that >> functionality in some language. > > You can still mimick the behavior of 'continue' using a named label and > 'GoTo'... >
Show quote
Hide quote
"cj" <cj@nospam.nospam> wrote in message lol Herfried is a very popular poster here :) As well as an MVP...he'll be news:%23H2GZK7RGHA.5924@TK2MSFTNGP09.phx.gbl... > Whowa! Your sure to get blasted for that idea. I hope you aren't using > your real name. :) I just might do that though. > > > Herfried K. Wagner [MVP] wrote: >> "cj" <cj@nospam.nospam> schrieb: >>> Unfortunately I'm using VB.Net 2003 right now and continue doesn't >>> appear to do that in 2003. I believe continue does have that >>> functionality in some language. >> >> You can still mimick the behavior of 'continue' using a named label and >> 'GoTo'... >> blasted for being both of those for sure <ducks> Naw, Herfried is a good poster and if he gets blasted... Mythran Wow, not just anyone but a respected member of the community
recommending me to use goto. :) That took guts! I hope the community still respects him. Well, in case you haven't read all the other branches of this message I can't seem to go against all these years of negative public opinion. I decided to use nested do loops. I still think this is one time goto is actually a practical, legitimate, and indeed inspired idea. I wish I had the guts to use it. Herfried, your opinions are always welcome in my posts. Mythran wrote: Show quoteHide quote > > "cj" <cj@nospam.nospam> wrote in message > news:%23H2GZK7RGHA.5924@TK2MSFTNGP09.phx.gbl... >> Whowa! Your sure to get blasted for that idea. I hope you aren't >> using your real name. :) I just might do that though. >> >> >> Herfried K. Wagner [MVP] wrote: >>> "cj" <cj@nospam.nospam> schrieb: >>>> Unfortunately I'm using VB.Net 2003 right now and continue doesn't >>>> appear to do that in 2003. I believe continue does have that >>>> functionality in some language. >>> >>> You can still mimick the behavior of 'continue' using a named label >>> and 'GoTo'... >>> > > lol Herfried is a very popular poster here :) As well as an MVP...he'll > be blasted for being both of those for sure <ducks> > > Naw, Herfried is a good poster and if he gets blasted... > > Mythran VB 6 doesn't have it either. What you see in VB 6 program is:
do if somecondition then ... ... end if loop In VB 2005 this would be do if not somecondition then continue ... ... loop It's awkward but it works. Also, it's interesting to note that the VB 2005 continue doesn't actually jump back to the start of the loop. It actually jumps to the end of the loop and lets the loop control jump back. Watch it in the debugger. Mike Ober. Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:%23ncLnG7RGHA.4956@TK2MSFTNGP09.phx.gbl... > "cj" <cj@nospam.nospam> schrieb: > > Unfortunately I'm using VB.Net 2003 right now and continue doesn't appear > > to do that in 2003. I believe continue does have that functionality in > > some language. > > You can still mimick the behavior of 'continue' using a named label and > 'GoTo'... > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> > > I could use lots of "if somecondition" nested together. But, IMHO by
the time you get to checking conditions in 5,6 or 7 places in the loop it makes for a very funny looking program with all the nested ifs. Things begin to get indented off the right side of the screen. Basically I'm starting the loop and if things go correctly I execute all code in it. But at say 6 places in the loop I have to check how things are going. If they are not going well I want to forget about processing the remainder of work in the loop and try the next iteration. Michael D. Ober wrote: Show quoteHide quote > VB 6 doesn't have it either. What you see in VB 6 program is: > > do > if somecondition then > ... > ... > end if > loop > > In VB 2005 this would be > > do > if not somecondition then continue > ... > ... > loop > > It's awkward but it works. Also, it's interesting to note that the VB 2005 > continue doesn't actually jump back to the start of the loop. It actually > jumps to the end of the loop and lets the loop control jump back. Watch it > in the debugger. > > Mike Ober. > > > "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message > news:%23ncLnG7RGHA.4956@TK2MSFTNGP09.phx.gbl... >> "cj" <cj@nospam.nospam> schrieb: >>> Unfortunately I'm using VB.Net 2003 right now and continue doesn't > appear >>> to do that in 2003. I believe continue does have that functionality in >>> some language. >> You can still mimick the behavior of 'continue' using a named label and >> 'GoTo'... >> >> -- >> M S Herfried K. Wagner >> M V P <URL:http://dotnet.mvps.org/> >> V B <URL:http://classicvb.org/petition/> >> >> > > > cj <cj@nospam.nospam> wrote in
news:#zyuFUDSGHA.2224@TK2MSFTNGP10.phx.gbl: You could always try structured programming:> Basically I'm starting the loop and if things go correctly I execute > all code in it. But at say 6 places in the loop I have to check how > things are going. If they are not going well I want to forget about > processing the remainder of work in the loop and try the next > iteration. Do While True carryOn = True if carryOn Then DoSomeProcessing() carryOn = Not ConditionMet() end if if carryOn Then DoSomeMoreProcessing() If Not AnotherCondition() Then carryOn = False End If end if if carryOn Then DoLastBitOfWork If FinalCondition > criterionDecided Then Exit Do End If End If Loop Hope that helps Tim F Yes, that works too but requires me to enclose every segment of the code
in if else statements checking to see if it's ok to do it. I did use this type of code in one place except I called it loopError and set it to False and if it remains false It does all the ifs. Strangely next to the non existent loop/continue statement goto would seem to create the most readable and compact code. The example in VB.net 2003's help for goto is an example of a bad use of goto. Tim Ferguson wrote: Show quoteHide quote > cj <cj@nospam.nospam> wrote in > news:#zyuFUDSGHA.2224@TK2MSFTNGP10.phx.gbl: > >> Basically I'm starting the loop and if things go correctly I execute >> all code in it. But at say 6 places in the loop I have to check how >> things are going. If they are not going well I want to forget about >> processing the remainder of work in the loop and try the next >> iteration. > > You could always try structured programming: > > > Do While True > carryOn = True > > if carryOn Then > DoSomeProcessing() > carryOn = Not ConditionMet() > > end if > > if carryOn Then > DoSomeMoreProcessing() > If Not AnotherCondition() Then > carryOn = False > End If > > end if > > if carryOn Then > DoLastBitOfWork > If FinalCondition > criterionDecided Then > Exit Do > End If > End If > > Loop > > > > Hope that helps > > > Tim F > > cj <cj@nospam.nospam> wrote in news:etzxgIHSGHA.5808@TK2MSFTNGP12.phx.gbl: Yebbut, Nobbut, Yebbut, Nobbut Yeah, you see... it's all about how far the > Strangely next to > the non existent loop/continue statement goto would seem to create the > most readable and compact code. Goto GetOutOfHereNow is from the :GetOutOfHereNow. In many implementations they end up a long way away, and it's the code-maintainer that comes along later and doesn't spot it. For my money, structured programming is all about putting code into little self-contained boxes, and any path that suddenly arrives at another point with several different possibilities for variables that have been initialised or not, files that have been opened or closed or not, etc etc is asking for trouble. YMMV of course. All the best Tim F Very true. I'd add that not only is it bad practice to have a GoTo too
far from the label, it is just as bad to have too many lines of code within an if, loop, do or whatever statement. If the top and bottom of the code are close enough to be enclosed in a do loop the goto wouldn't be a problem. Also lets not forget what others have pointed out as well. Proper naming is critical in anything. GoTo GetOutOfhere Now wouldn't be as nice as GoTo BottomOfContinueLoop assuming I'm using Do, While Continue as the loop. Heck for that matter Continue is a bad choice of names in most situations. It'd be better to use Do, While GetNewShippingRecords or something. Except that Continue is easily readable and understandable in this specific app. I'd further mention, and it's a pet peeve of mine, that I've seen these little self contained boxes used to the point that they make code unreadable. Some folks, and I'm not insinuating your one of them, use them to such a point that he main code has nothing in it but calls and then you find all it does is call others. Your jumping all over the place to see what the next subroutine does and it becomes its own form of spaghetti code. If you don't have to call a routine but from one place you might not need to put it in a routine. Might, I said. Sometimes it's good of course, like to remove a huge section of distinct code to keep routines short enough to read. Tim Ferguson wrote: Show quoteHide quote > cj <cj@nospam.nospam> wrote in news:etzxgIHSGHA.5808@TK2MSFTNGP12.phx.gbl: > >> Strangely next to >> the non existent loop/continue statement goto would seem to create the >> most readable and compact code. > > Yebbut, Nobbut, Yebbut, Nobbut Yeah, you see... it's all about how far the > Goto GetOutOfHereNow is from the :GetOutOfHereNow. In many implementations > they end up a long way away, and it's the code-maintainer that comes along > later and doesn't spot it. > > For my money, structured programming is all about putting code into little > self-contained boxes, and any path that suddenly arrives at another point > with several different possibilities for variables that have been > initialised or not, files that have been opened or closed or not, etc etc > is asking for trouble. YMMV of course. > > All the best > > > Tim F > cj wrote:
> When I'm inside a do while loop sometimes it's necessary to jump out The meaning of "continue" is to start the *next* iteration immediately and> of the loop using exit do. I'm also used to being able to jump back > and begin the loop again. Not sure which language my memories are of > but I think I just said loop somewhere inside the loop and it > immediately jumped back to the start of the loop and began again. I > can't seem to do that in .net. I this functionality available? bypass any further code in the loop body. If you want to continue the current operation then you'd either have an inner loop or use a goto. If you want to completely restart the loop then you'd be best enclosing it in an outer loop. You mustn't use the goto idea for that one. Jumping out of the loop to before the loop - that should get you those frowns. ;o) I understand the functionality of continue. I also understand it
doesn't work in VB.Net 2003, right? It does in 2005, right? I understand why goto is not generally a good thing but just because a command has been frequently misused in the past doesn't make it bad. I admire Herfried for suggesting goto. It seems like a perfect use. Still I'm having a hard time using it because other say it's wrong. It's a real conundrum. There has to be a way that socially acceptable and personally feels right. An outer loop is what I have started with because goto has been out of my vocabulary since 87. Still I just don't like seeing one loop inserted inside another just for this functionality. It looks funny and just seems wrong. I'll come up with a better way. Something in the nature subroutines and flags etc. I'll get something that feels better when I get back to work tomorrow. dotNuttah wrote: Show quoteHide quote > cj wrote: >> When I'm inside a do while loop sometimes it's necessary to jump out >> of the loop using exit do. I'm also used to being able to jump back >> and begin the loop again. Not sure which language my memories are of >> but I think I just said loop somewhere inside the loop and it >> immediately jumped back to the start of the loop and began again. I >> can't seem to do that in .net. I this functionality available? > > The meaning of "continue" is to start the *next* iteration immediately and > bypass any further code in the loop body. If you want to continue the > current operation then you'd either have an inner loop or use a goto. If you > want to completely restart the loop then you'd be best enclosing it in an > outer loop. You mustn't use the goto idea for that one. Jumping out of the > loop to before the loop - that should get you those frowns. ;o) > > > cj,
I don't agree with you and there is in my opinion enough written in this newsgroup about that. Can't you not use a Select Case. Probably makes that your program again much readable then. Cor Show quoteHide quote "cj" <cj@nospam.nospam> schreef in bericht news:eiDGYQ9RGHA.1688@TK2MSFTNGP11.phx.gbl... >I understand the functionality of continue. I also understand it doesn't >work in VB.Net 2003, right? It does in 2005, right? > > I understand why goto is not generally a good thing but just because a > command has been frequently misused in the past doesn't make it bad. I > admire Herfried for suggesting goto. It seems like a perfect use. Still > I'm having a hard time using it because other say it's wrong. It's a real > conundrum. There has to be a way that socially acceptable and personally > feels right. > > An outer loop is what I have started with because goto has been out of my > vocabulary since 87. Still I just don't like seeing one loop inserted > inside another just for this functionality. It looks funny and just seems > wrong. I'll come up with a better way. Something in the nature > subroutines and flags etc. I'll get something that feels better when I > get back to work tomorrow. > > > dotNuttah wrote: >> cj wrote: >>> When I'm inside a do while loop sometimes it's necessary to jump out >>> of the loop using exit do. I'm also used to being able to jump back >>> and begin the loop again. Not sure which language my memories are of >>> but I think I just said loop somewhere inside the loop and it >>> immediately jumped back to the start of the loop and began again. I >>> can't seem to do that in .net. I this functionality available? >> >> The meaning of "continue" is to start the *next* iteration immediately >> and >> bypass any further code in the loop body. If you want to continue the >> current operation then you'd either have an inner loop or use a goto. If >> you >> want to completely restart the loop then you'd be best enclosing it in an >> outer loop. You mustn't use the goto idea for that one. Jumping out of >> the >> loop to before the loop - that should get you those frowns. ;o) >> >> Sorry to hear you disagree. Anyway, it's just an opinion. Everyone has
one. No, the select case would not work in this situation at all. Cor Ligthert [MVP] wrote: Show quoteHide quote > cj, > > I don't agree with you and there is in my opinion enough written in this > newsgroup about that. > > Can't you not use a Select Case. Probably makes that your program again much > readable then. > > Cor > > "cj" <cj@nospam.nospam> schreef in bericht > news:eiDGYQ9RGHA.1688@TK2MSFTNGP11.phx.gbl... >> I understand the functionality of continue. I also understand it doesn't >> work in VB.Net 2003, right? It does in 2005, right? >> >> I understand why goto is not generally a good thing but just because a >> command has been frequently misused in the past doesn't make it bad. I >> admire Herfried for suggesting goto. It seems like a perfect use. Still >> I'm having a hard time using it because other say it's wrong. It's a real >> conundrum. There has to be a way that socially acceptable and personally >> feels right. >> >> An outer loop is what I have started with because goto has been out of my >> vocabulary since 87. Still I just don't like seeing one loop inserted >> inside another just for this functionality. It looks funny and just seems >> wrong. I'll come up with a better way. Something in the nature >> subroutines and flags etc. I'll get something that feels better when I >> get back to work tomorrow. >> >> >> dotNuttah wrote: >>> cj wrote: >>>> When I'm inside a do while loop sometimes it's necessary to jump out >>>> of the loop using exit do. I'm also used to being able to jump back >>>> and begin the loop again. Not sure which language my memories are of >>>> but I think I just said loop somewhere inside the loop and it >>>> immediately jumped back to the start of the loop and began again. I >>>> can't seem to do that in .net. I this functionality available? >>> The meaning of "continue" is to start the *next* iteration immediately >>> and >>> bypass any further code in the loop body. If you want to continue the >>> current operation then you'd either have an inner loop or use a goto. If >>> you >>> want to completely restart the loop then you'd be best enclosing it in an >>> outer loop. You mustn't use the goto idea for that one. Jumping out of >>> the >>> loop to before the loop - that should get you those frowns. ;o) >>> >>> > cj wrote:
> I understand the functionality of continue. I also understand it I don't know about 2005. ;-)> doesn't work in VB.Net 2003, right? It does in 2005, right? > I understand why goto is not generally a good thing but just because a I've never thought goto was bad. I think that bad use of it is bad. :-D> command has been frequently misused in the past doesn't make it bad. > I admire Herfried for suggesting goto. It seems like a perfect use. > Still I'm having a hard time using it because other say it's wrong. You're the only one that can change your personal perspective on it.> It's a real conundrum. There has to be a way that socially acceptable > and personally feels right. Socially it really depends on who's opinion you're giving value to. I wonder what would happen if you change your personal perspective to let you use goto when the situation warrants it, and give it more priority than "social" opinion. :-)) > An outer loop is what I have started with because goto has been out of I often use that method but yep, it looks clumsy, clumsy and makes the code> my vocabulary since 87. Still I just don't like seeing one loop > inserted inside another just for this functionality. It looks funny > and just seems wrong. cry out for some decent syntax for this structure. I can't remember where it was but one language I came across had "break" (or exit loop) and "continue" with an index. The index was the level of the loop that the break or continue was applied to. Very handy. To make the goto easy to use for a reader you have to make it stand out in the code, else the reader might be hunting all over for it and that can look clumsy too. Do you have the label in column one or indent it (and hence bury it, to a degree) in the code which it labels? :-/ A choice of name that says where to go/look, like "goto bottom_of_loop" helps. > I'll come up with a better way. Something in Aye, it sounds as if the loop body contains enough that a subroutine would> the nature subroutines and flags etc. be appropriate anyway, perhaps. Show quoteHide quote >I'll get something that feels better when I get back to work tomorrow. :-)) > dotNuttah wrote: >> cj wrote: >>> When I'm inside a do while loop sometimes it's necessary to jump out >>> of the loop using exit do. I'm also used to being able to jump back >>> and begin the loop again. Not sure which language my memories are >>> of but I think I just said loop somewhere inside the loop and it >>> immediately jumped back to the start of the loop and began again. I >>> can't seem to do that in .net. I this functionality available? >> >> The meaning of "continue" is to start the *next* iteration >> immediately and bypass any further code in the loop body. If you >> want to continue the current operation then you'd either have an >> inner loop or use a goto. If you want to completely restart the loop >> then you'd be best enclosing it in an outer loop. You mustn't use >> the goto idea for that one. Jumping out of the loop to before the >> loop - that should get you those frowns. ;o) Thanks for all the support. I posted this to Mythran also but I wanted
to make sure you saw it as well. In reviewing some of this just now I see one thing that would need to be considered in choosing goto vs nested loops. I'm not sure but I suspect the functionality of the not in VB.net 2003 loop/continue statement would work more like the nested loops alternative than the goto alternative. In a nested loop situation the exit sub would exit the inner loop and therefore you'd re-enter the loop with any variables declared inside the loop being refreshed, for lack of a better word. I haven't tried but I get the impression from the help that goto can't be used to jump outside a loop (to the line above it) so it could be restarted, hence goto could only be used to go to the first line inside the loop. variables inside the loop would not be refreshed they would be as they existed before the goto was executed. This could be good or it could be bad. Just has to be checked into and considered. dotNuttah wrote: Show quoteHide quote > cj wrote: >> I understand the functionality of continue. I also understand it >> doesn't work in VB.Net 2003, right? It does in 2005, right? > > I don't know about 2005. ;-) > >> I understand why goto is not generally a good thing but just because a >> command has been frequently misused in the past doesn't make it bad. >> I admire Herfried for suggesting goto. It seems like a perfect use. > > I've never thought goto was bad. I think that bad use of it is bad. :-D > >> Still I'm having a hard time using it because other say it's wrong. >> It's a real conundrum. There has to be a way that socially acceptable >> and personally feels right. > > You're the only one that can change your personal perspective on it. > Socially it really depends on who's opinion you're giving value to. I wonder > what would happen if you change your personal perspective to let you use > goto when the situation warrants it, and give it more priority than "social" > opinion. :-)) > >> An outer loop is what I have started with because goto has been out of >> my vocabulary since 87. Still I just don't like seeing one loop >> inserted inside another just for this functionality. It looks funny >> and just seems wrong. > > I often use that method but yep, it looks clumsy, clumsy and makes the code > cry out for some decent syntax for this structure. I can't remember where it > was but one language I came across had "break" (or exit loop) and "continue" > with an index. The index was the level of the loop that the break or > continue was applied to. Very handy. > > To make the goto easy to use for a reader you have to make it stand out in > the code, else the reader might be hunting all over for it and that can look > clumsy too. Do you have the label in column one or indent it (and hence bury > it, to a degree) in the code which it labels? :-/ A choice of name that says > where to go/look, like "goto bottom_of_loop" helps. > >> I'll come up with a better way. Something in >> the nature subroutines and flags etc. > > Aye, it sounds as if the loop body contains enough that a subroutine would > be appropriate anyway, perhaps. > >> I'll get something that feels better when I get back to work tomorrow. > > :-)) > >> dotNuttah wrote: >>> cj wrote: >>>> When I'm inside a do while loop sometimes it's necessary to jump out >>>> of the loop using exit do. I'm also used to being able to jump back >>>> and begin the loop again. Not sure which language my memories are >>>> of but I think I just said loop somewhere inside the loop and it >>>> immediately jumped back to the start of the loop and began again. I >>>> can't seem to do that in .net. I this functionality available? >>> The meaning of "continue" is to start the *next* iteration >>> immediately and bypass any further code in the loop body. If you >>> want to continue the current operation then you'd either have an >>> inner loop or use a goto. If you want to completely restart the loop >>> then you'd be best enclosing it in an outer loop. You mustn't use >>> the goto idea for that one. Jumping out of the loop to before the >>> loop - that should get you those frowns. ;o) > > Ooops, I refered to exit sub where I meant exit do.
cj wrote: Show quoteHide quote > Thanks for all the support. I posted this to Mythran also but I wanted > to make sure you saw it as well. > > In reviewing some of this just now I see one thing that would need to be > considered in choosing goto vs nested loops. I'm not sure but I suspect > the functionality of the not in VB.net 2003 loop/continue statement > would work more like the nested loops alternative than the goto > alternative. In a nested loop situation the exit sub would exit the > inner loop and therefore you'd re-enter the loop with any variables > declared inside the loop being refreshed, for lack of a better word. I > haven't tried but I get the impression from the help that goto can't be > used to jump outside a loop (to the line above it) so it could be > restarted, hence goto could only be used to go to the first line inside > the loop. variables inside the loop would not be refreshed they would > be as they existed before the goto was executed. This could be good or > it could be bad. Just has to be checked into and considered. > > > dotNuttah wrote: >> cj wrote: >>> I understand the functionality of continue. I also understand it >>> doesn't work in VB.Net 2003, right? It does in 2005, right? >> >> I don't know about 2005. ;-) >> >>> I understand why goto is not generally a good thing but just because a >>> command has been frequently misused in the past doesn't make it bad. >>> I admire Herfried for suggesting goto. It seems like a perfect use. >> >> I've never thought goto was bad. I think that bad use of it is bad. :-D >> >>> Still I'm having a hard time using it because other say it's wrong. >>> It's a real conundrum. There has to be a way that socially acceptable >>> and personally feels right. >> >> You're the only one that can change your personal perspective on it. >> Socially it really depends on who's opinion you're giving value to. I >> wonder >> what would happen if you change your personal perspective to let you use >> goto when the situation warrants it, and give it more priority than >> "social" >> opinion. :-)) >> >>> An outer loop is what I have started with because goto has been out of >>> my vocabulary since 87. Still I just don't like seeing one loop >>> inserted inside another just for this functionality. It looks funny >>> and just seems wrong. >> >> I often use that method but yep, it looks clumsy, clumsy and makes the >> code >> cry out for some decent syntax for this structure. I can't remember >> where it >> was but one language I came across had "break" (or exit loop) and >> "continue" >> with an index. The index was the level of the loop that the break or >> continue was applied to. Very handy. >> >> To make the goto easy to use for a reader you have to make it stand >> out in >> the code, else the reader might be hunting all over for it and that >> can look >> clumsy too. Do you have the label in column one or indent it (and >> hence bury >> it, to a degree) in the code which it labels? :-/ A choice of name >> that says >> where to go/look, like "goto bottom_of_loop" helps. >> >>> I'll come up with a better way. Something in >>> the nature subroutines and flags etc. >> >> Aye, it sounds as if the loop body contains enough that a subroutine >> would >> be appropriate anyway, perhaps. >> >>> I'll get something that feels better when I get back to work tomorrow. >> >> :-)) >> >>> dotNuttah wrote: >>>> cj wrote: >>>>> When I'm inside a do while loop sometimes it's necessary to jump out >>>>> of the loop using exit do. I'm also used to being able to jump back >>>>> and begin the loop again. Not sure which language my memories are >>>>> of but I think I just said loop somewhere inside the loop and it >>>>> immediately jumped back to the start of the loop and began again. I >>>>> can't seem to do that in .net. I this functionality available? >>>> The meaning of "continue" is to start the *next* iteration >>>> immediately and bypass any further code in the loop body. If you >>>> want to continue the current operation then you'd either have an >>>> inner loop or use a goto. If you want to completely restart the loop >>>> then you'd be best enclosing it in an outer loop. You mustn't use >>>> the goto idea for that one. Jumping out of the loop to before the >>>> loop - that should get you those frowns. ;o) >> >>
Show quote
Hide quote
"cj" <cj@nospam.nospam> wrote in message Depends how you write it...news:%23PqmYTHSGHA.4600@TK2MSFTNGP11.phx.gbl... > Thanks for all the support. I posted this to Mythran also but I wanted to > make sure you saw it as well. > > In reviewing some of this just now I see one thing that would need to be > considered in choosing goto vs nested loops. I'm not sure but I suspect > the functionality of the not in VB.net 2003 loop/continue statement would > work more like the nested loops alternative than the goto alternative. In > a nested loop situation the exit sub would exit the inner loop and > therefore you'd re-enter the loop with any variables declared inside the > loop being refreshed, for lack of a better word. I haven't tried but I > get the impression from the help that goto can't be used to jump outside a > loop (to the line above it) so it could be restarted, hence goto could > only be used to go to the first line inside the loop. variables inside > the loop would not be refreshed they would be as they existed before the > goto was executed. This could be good or it could be bad. Just has to be > checked into and considered. > > Your explanation is correct if written this way: [begin loop] [:MyLabel] [do stuff] [goto MyLabel] [end loop] You explanation is in-correct if written this way: [begin loop] [goto MyLabel] [do stuff] [:MyLabel] [end loop] So placing the label right before the loop re-starts will make it iterate/increment properly :) Mythran Quite true indeed.
Mythran wrote: Show quoteHide quote > > "cj" <cj@nospam.nospam> wrote in message > news:%23PqmYTHSGHA.4600@TK2MSFTNGP11.phx.gbl... >> Thanks for all the support. I posted this to Mythran also but I >> wanted to make sure you saw it as well. >> >> In reviewing some of this just now I see one thing that would need to >> be considered in choosing goto vs nested loops. I'm not sure but I >> suspect the functionality of the not in VB.net 2003 loop/continue >> statement would work more like the nested loops alternative than the >> goto alternative. In a nested loop situation the exit sub would exit >> the inner loop and therefore you'd re-enter the loop with any >> variables declared inside the loop being refreshed, for lack of a >> better word. I haven't tried but I get the impression from the help >> that goto can't be used to jump outside a loop (to the line above it) >> so it could be restarted, hence goto could only be used to go to the >> first line inside the loop. variables inside the loop would not be >> refreshed they would be as they existed before the goto was executed. >> This could be good or it could be bad. Just has to be checked into >> and considered. >> >> > > Depends how you write it... > > Your explanation is correct if written this way: > > [begin loop] > [:MyLabel] > [do stuff] > [goto MyLabel] > [end loop] > > You explanation is in-correct if written this way: > > [begin loop] > [goto MyLabel] > [do stuff] > [:MyLabel] > [end loop] > > So placing the label right before the loop re-starts will make it > iterate/increment properly :) > > Mythran > > An outer loop is what I have started with because goto has been out of my Never do batch files eh? Like you said, it's not a bad command, just a > vocabulary since 87. misused command. And if you want the functionality of "Continue" without using the IF's, then Goto is the perfect command for what you are trying to accomplish. Mythran Gee, I'm getting lots of support on this topic. Sounds like something
that needs discussing. I've done lots of batch files and you sure do have to get, shall we say creative, to branch and make decisions. Look familiar: @echo off if %1. == full. goto full if %1. == FULL. goto full goto mod :full In reviewing some of this just now I see one thing that would need to be considered in choosing goto vs nested loops. I'm not sure but I suspect the functionality of the not in VB.net 2003 loop/continue statement would work more like the nested loops alternative than the goto alternative. In a nested loop situation the exit sub would exit the inner loop and therefore you'd re-enter the loop with any variables declared inside the loop being refreshed, for lack of a better word. I haven't tried but I get the impression from the help that goto can't be used to jump outside a loop (to the line above it) so it could be restarted, hence goto could only be used to go to the first line inside the loop. variables inside the loop would not be refreshed they would be as they existed before the goto was executed. This could be good or it could be bad. Just has to be checked into and considered. Mythran wrote: Show quoteHide quote >> An outer loop is what I have started with because goto has been out of >> my vocabulary since 87. > > Never do batch files eh? Like you said, it's not a bad command, just a > misused command. And if you want the functionality of "Continue" > without using the IF's, then Goto is the perfect command for what you > are trying to accomplish. > > Mythran > Ooops, I said exit sub where I meant exit do.
cj wrote: Show quoteHide quote > Gee, I'm getting lots of support on this topic. Sounds like something > that needs discussing. I've done lots of batch files and you sure do > have to get, shall we say creative, to branch and make decisions. > > Look familiar: > > @echo off > if %1. == full. goto full > if %1. == FULL. goto full > goto mod > :full > > In reviewing some of this just now I see one thing that would need to be > considered in choosing goto vs nested loops. I'm not sure but I suspect > the functionality of the not in VB.net 2003 loop/continue statement > would work more like the nested loops alternative than the goto > alternative. In a nested loop situation the exit sub would exit the > inner loop and therefore you'd re-enter the loop with any variables > declared inside the loop being refreshed, for lack of a better word. I > haven't tried but I get the impression from the help that goto can't be > used to jump outside a loop (to the line above it) so it could be > restarted, hence goto could only be used to go to the first line inside > the loop. variables inside the loop would not be refreshed they would > be as they existed before the goto was executed. This could be good or > it could be bad. Just has to be checked into and considered. > > > Mythran wrote: >>> An outer loop is what I have started with because goto has been out >>> of my vocabulary since 87. >> >> Never do batch files eh? Like you said, it's not a bad command, just >> a misused command. And if you want the functionality of "Continue" >> without using the IF's, then Goto is the perfect command for what you >> are trying to accomplish. >> >> Mythran >> cj wrote:
> When I'm inside a do while loop sometimes it's necessary to jump out of Did you use Clipper(xBase) by any chance? There a loop contruction there > the loop using exit do. I'm also used to being able to jump back and > begin the loop again. Not sure which language my memories are of but I > think I just said loop somewhere inside the loop and it immediately > jumped back to the start of the loop and began again. I can't seem to > do that in .net. I this functionality available? like you describe it. I'm missing it too in VB. When porting some routines over from xBase++ I've run into this problem and had to rethink the logic.. too bad :( -- Rinze van Huizen C-Services Holland b.v Yes, DOS based Clipper for over 7 years. I think that loop construction
is in several other languages too. Someone here suggested it's in C as well. And it sounds like it's in VB .Net 2005. Glad to hear from someone else who's heard of Clipper. C-Services Holland b.v. wrote: Show quoteHide quote > cj wrote: >> When I'm inside a do while loop sometimes it's necessary to jump out >> of the loop using exit do. I'm also used to being able to jump back >> and begin the loop again. Not sure which language my memories are of >> but I think I just said loop somewhere inside the loop and it >> immediately jumped back to the start of the loop and began again. I >> can't seem to do that in .net. I this functionality available? > > Did you use Clipper(xBase) by any chance? There a loop contruction there > like you describe it. I'm missing it too in VB. When porting some > routines over from xBase++ I've run into this problem and had to rethink > the logic.. too bad :( > > How about making the loop in its own procedure that can take the appropriate
arguments you'll need to use to determine if the loop "is going well and should continue"? You can still exit from the loop (or from the sub if the loop is in one) if you need to and you'd be able to re-call the loop/procedure and pass it what it needs to begin again. Show quoteHide quote "cj" <cj@nospam.nospam> wrote in message news:ex3Rt36RGHA.1572@tk2msftngp13.phx.gbl... > When I'm inside a do while loop sometimes it's necessary to jump out of > the loop using exit do. I'm also used to being able to jump back and > begin the loop again. Not sure which language my memories are of but I > think I just said loop somewhere inside the loop and it immediately jumped > back to the start of the loop and began again. I can't seem to do that in > .net. I this functionality available? I thought about that this AM but after all the thought I have a double
do loop. do do . if something exit do . . . if something exit do . if something exit do . while innerLoop while continue Not beautiful but it was time to make a decision and move on. Couldn't bring myself to use goto. Scott M. wrote: Show quoteHide quote > How about making the loop in its own procedure that can take the appropriate > arguments you'll need to use to determine if the loop "is going well and > should continue"? > > You can still exit from the loop (or from the sub if the loop is in one) if > you need to and you'd be able to re-call the loop/procedure and pass it what > it needs to begin again. > > "cj" <cj@nospam.nospam> wrote in message > news:ex3Rt36RGHA.1572@tk2msftngp13.phx.gbl... >> When I'm inside a do while loop sometimes it's necessary to jump out of >> the loop using exit do. I'm also used to being able to jump back and >> begin the loop again. Not sure which language my memories are of but I >> think I just said loop somewhere inside the loop and it immediately jumped >> back to the start of the loop and began again. I can't seem to do that in >> .net. I this functionality available? > > cj,
You can do it without a continue, a goto or whatever. I have once made a sample for that when Marina told I could not. It is unreadable, however. Therefore I do not show it here. It was almost the same as yours, although she had made an impossible chalenge as sample. Cor It sure has been nice discussing this here. I guess I found a subject
that many folks have encountered. There are lots of way to tackle the problem. The continue/loop functionality I hoped existed in VB.Net 2003 for the do loop structure would be a perfect for this job. Since it isn't I keep looking to find the next most perfect solution. Still I don't have infinite time so I went with the nested do loop. It's not perfect but it'll get the job done. When I have more time I'm going to look into the goto some. Might have to put it back into service in this one specific type of situation. I need to get 2005 loaded and see what's in it sometime but that'll probably be a few more months. Cor Ligthert [MVP] wrote: Show quoteHide quote > cj, > > You can do it without a continue, a goto or whatever. I have once made a > sample for that when Marina told I could not. It is unreadable, however. > Therefore I do not show it here. > > It was almost the same as yours, although she had made an impossible > chalenge as sample. > > Cor > > I think you may have misunderstood the suggestion for using goto. Make
the goto go to the end of the loop, not the beginning, and you get exactly the functionality of a continue statement, no messy inner loop. Ex: do . if something goto LoopContinue . . . if something goto LoopContinue . if something goto LoopContinue . LoopContinue: while continue cj wrote: Show quoteHide quote > I thought about that this AM but after all the thought I have a double > do loop. > > do > do > . > if something exit do > . > . > . > if something exit do > . > if something exit do > . > while innerLoop > while continue > > Not beautiful but it was time to make a decision and move on. Couldn't > bring myself to use goto. > > > > Scott M. wrote: >> How about making the loop in its own procedure that can take the >> appropriate arguments you'll need to use to determine if the loop "is >> going well and should continue"? >> >> You can still exit from the loop (or from the sub if the loop is in >> one) if you need to and you'd be able to re-call the loop/procedure >> and pass it what it needs to begin again. >> >> "cj" <cj@nospam.nospam> wrote in message >> news:ex3Rt36RGHA.1572@tk2msftngp13.phx.gbl... >>> When I'm inside a do while loop sometimes it's necessary to jump out >>> of the loop using exit do. I'm also used to being able to jump back >>> and begin the loop again. Not sure which language my memories are of >>> but I think I just said loop somewhere inside the loop and it >>> immediately jumped back to the start of the loop and began again. I >>> can't seem to do that in .net. I this functionality available? >> >> Yes, that'll also work.
Sebastian wrote: Show quoteHide quote > I think you may have misunderstood the suggestion for using goto. Make > the goto go to the end of the loop, not the beginning, and you get > exactly the functionality of a continue statement, no messy inner loop. > > Ex: > do > . > if something goto LoopContinue > . > . > . > if something goto LoopContinue > . > if something goto LoopContinue > . > > LoopContinue: > while continue > > > cj wrote: >> I thought about that this AM but after all the thought I have a double >> do loop. >> >> do >> do >> . >> if something exit do >> . >> . >> . >> if something exit do >> . >> if something exit do >> . >> while innerLoop >> while continue >> >> Not beautiful but it was time to make a decision and move on. >> Couldn't bring myself to use goto. >> >> >> >> Scott M. wrote: >>> How about making the loop in its own procedure that can take the >>> appropriate arguments you'll need to use to determine if the loop "is >>> going well and should continue"? >>> >>> You can still exit from the loop (or from the sub if the loop is in >>> one) if you need to and you'd be able to re-call the loop/procedure >>> and pass it what it needs to begin again. >>> >>> "cj" <cj@nospam.nospam> wrote in message >>> news:ex3Rt36RGHA.1572@tk2msftngp13.phx.gbl... >>>> When I'm inside a do while loop sometimes it's necessary to jump out >>>> of the loop using exit do. I'm also used to being able to jump back >>>> and begin the loop again. Not sure which language my memories are >>>> of but I think I just said loop somewhere inside the loop and it >>>> immediately jumped back to the start of the loop and began again. I >>>> can't seem to do that in .net. I this functionality available? >>> >>>
length of string
Adding Button Programatically - have an answer??? XML to ODBC Sub Main is not waiting!!!?? Visual Studio 2003 Menu on form.vb Adding data to database including resource files Sending web email XmlDocument object to string - plase help with unusual character! best way to tell if a date is not assigned? |
|||||||||||||||||||||||