PC Review Forums Newsgroups Microsoft DotNet Microsoft VB .NET I miss loop

Reply

I miss loop

 
Thread Tools Rate Thread
Old 14-03-2006, 09:26 PM   #1
cj
Guest
 
Posts: n/a
Default I miss loop


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?
  Reply With Quote
Old 14-03-2006, 09:43 PM   #2
Mythran
Guest
 
Posts: n/a
Default Re: I miss loop


"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

  Reply With Quote
Old 14-03-2006, 09:50 PM   #3
cj
Guest
 
Posts: n/a
Default Re: I miss loop

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:
>
> "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
>

  Reply With Quote
Old 14-03-2006, 09:52 PM   #4
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a
Default Re: I miss loop

"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/>

  Reply With Quote
Old 14-03-2006, 09:59 PM   #5
cj
Guest
 
Posts: n/a
Default Re: I miss loop

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'...
>

  Reply With Quote
Old 14-03-2006, 10:25 PM   #6
dotNuttah
Guest
 
Posts: n/a
Default Re: I miss loop

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)



  Reply With Quote
Old 15-03-2006, 01:59 AM   #7
cj
Guest
 
Posts: n/a
Default Re: I miss loop

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)
>
>
>

  Reply With Quote
Old 15-03-2006, 02:57 AM   #8
Michael D. Ober
Guest
 
Posts: n/a
Default Re: I miss loop

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/>
>
>




  Reply With Quote
Old 15-03-2006, 06:27 AM   #9
Cor Ligthert [MVP]
Guest
 
Posts: n/a
Default Re: I miss loop

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)
>>
>>


  Reply With Quote
Old 15-03-2006, 12:33 PM   #10
C-Services Holland b.v.
Guest
 
Posts: n/a
Default Re: I miss loop

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


--
Rinze van Huizen
C-Services Holland b.v
  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off