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?
Mar 14 '06
32 2606
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: "cj" <cj@nospam.nosp am> wrote in message news:%2******** ********@TK2MSF TNGP09.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.nosp am> 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
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: cj <cj@nospam.nosp am> wrote in news:#z******** ******@TK2MSFTN GP10.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 DoSomeProcessin g() carryOn = Not ConditionMet()
end if
if carryOn Then DoSomeMoreProce ssing() If Not AnotherConditio n() Then carryOn = False End If
end if
if carryOn Then DoLastBitOfWork If FinalCondition > criterionDecide d Then Exit Do End If End If
Loop Hope that helps
Tim F
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
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)
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: 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
Ooops, I refered to exit sub where I meant exit do.
cj wrote: 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)
Ooops, I said exit sub where I meant exit do.
cj wrote: 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
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
"cj" <cj@nospam.nosp am> wrote in message
news:%2******** ********@TK2MSF TNGP11.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
Quite true indeed.
Mythran wrote: "cj" <cj@nospam.nosp am> wrote in message news:%2******** ********@TK2MSF TNGP11.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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: F. GEIGER |
last post by:
When I start a py2exe-ed application I get the error
'ascii' codec can't encode character u'\xe9' in position 10: ordinal not in
range(128)
This is how I run py2exe:
setup.py py2exe -O1 --packages encodings
This is how the .po-file looks like:
|
by: John Bailo |
last post by:
Doing some c# client programming in VS.net
One thing I miss is that in the code view I could set the focus to a
form object in the left hand drop down ( like a TreeView control ) and
then the right hand drop down would expose only the properties and
events associated with that control.
I don't see that in VS.NET
|
by: ibm_97 |
last post by:
DB2 8.2
I try to add a column into a table. I think the procedure inside DB2
is:
1. Create a temporary table which has the old table stucture and data.
2. Drop the original table
3. Create the new table with the added column
4. Insert data back into the new table from that temporary table.
|
by: [Yosi] |
last post by:
Hi,
I create a thread which load DLL and have DLL function call,this Dll
function takes a lot of time.
My Question is , if I request Thread.Susspend(), and the thread is inside
the Dll function (Dll function not finished yet, and thread function wait for
this function (DLL)call to compleate), what will happen ? is this will
susspend also the Dll function execution ? or will delay the susspend untill
this function returned ?
Thx
|
by: kmounkhaty |
last post by:
Hi Guru,
My profiler trace does not display SP:CACHEMISS event, even thought I
drop store proc, clear both data cache and buffer cache but still does
not work.
Every thing works fine like: cachehit,
cacheinsert,cacheremove,executecontexthit etc...
Is there any special option that I need to turn it on?
| |
by: Useful Info |
last post by:
Like on 9/11, the Federal Government apparently WANTED people to die
at the hands of Cho at VA Tech, because they told campus police not to
pursue Cho after the double homicide occurred.
Story via
http://Muvy.org
|
by: anukedari |
last post by:
Hi,
Could any boby please help to get the answers for the following questions:
Is Apache always sends "X-Cache:MISS" header even when caching is off (disable)? or
Can we say that cache settings are enable if it sends "X-Cache:MISS" header in the response?
Your help would be appreciated.
|
by: manikandan |
last post by:
dont miss it just open
dont miss it just open
dont miss it just open
#############################
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
| |
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |