By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,934 Members | 1,692 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,934 IT Pros & Developers. It's quick & easy.

How Do You Make a Loop Iterate Early Without Using GoTo?

P: n/a
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob
Nov 21 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi,

What is wrong with this.
For Each Thing As OFI In FileInfo
If Thing.Displayed = True Then
If yada yada yada Then
TextBox2.Text = Thing.Name
End If
End If
Next Thing
Ken
-----------------------
"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:lk********************************@4ax.com...
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob
Nov 21 '05 #2

P: n/a
Thanks Ken. Yes. I meant to say in my post that I knew I could avoid
the GoTo by restructuring the If. And I suppose that even works in
general. BUT ... I am still wondering if there is some language
construct specifically for this. I also meant to say that I was
looking for the equivalent of the C/C++ continue statement.

But you would have mentioned the VB equivalent of the the C/C++
continue statement in your response, so I am gathering that VB does
not have such a construct. I guess I can live without it.

Thanks again, Bob

On Sun, 10 Oct 2004 19:11:54 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

What is wrong with this.
For Each Thing As OFI In FileInfo
If Thing.Displayed = True Then
If yada yada yada Then
TextBox2.Text = Thing.Name
End If
End If
Next Thing
Ken
-----------------------
"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:lk********************************@4ax.com.. .
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob


Nov 21 '05 #3

P: n/a
Any number of Exit For statements may be placed anywhere in the loop as an
alternative way to exit. Exit For is often used after evaluating some
condition, for example with an If...Then...Else statement, and transfers
control to the statement immediately following Next.

-L
"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:lk********************************@4ax.com...
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob

Nov 21 '05 #4

P: n/a
Bob,
You will need to wait for VS.NET 2005 (aka Whidbey, due out in later in
2005) for the Continue statement in VB.NET.

For information on VS.NET 2005 see: http://lab.msdn.microsoft.com/vs2005/

For information on the new Continue keyword see:
http://msdn2.microsoft.com/library/801hyx6f.aspx

Hope this helps
Jay

"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:pe********************************@4ax.com...
Thanks Ken. Yes. I meant to say in my post that I knew I could avoid
the GoTo by restructuring the If. And I suppose that even works in
general. BUT ... I am still wondering if there is some language
construct specifically for this. I also meant to say that I was
looking for the equivalent of the C/C++ continue statement.

But you would have mentioned the VB equivalent of the the C/C++
continue statement in your response, so I am gathering that VB does
not have such a construct. I guess I can live without it.

Thanks again, Bob

On Sun, 10 Oct 2004 19:11:54 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

What is wrong with this.
For Each Thing As OFI In FileInfo
If Thing.Displayed = True Then
If yada yada yada Then
TextBox2.Text = Thing.Name
End If
End If
Next Thing
Ken
-----------------------
"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:lk********************************@4ax.com. ..
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob

Nov 21 '05 #5

P: n/a
What he is asking for is a way to skip to the end of the for-next loop
and immediately go to the next item, not exit the loop.
Locke Nash Cole wrote:
Any number of Exit For statements may be placed anywhere in the loop as an
alternative way to exit. Exit For is often used after evaluating some
condition, for example with an If...Then...Else statement, and transfers
control to the statement immediately following Next.

-L
"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:lk********************************@4ax.com...
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob


Nov 21 '05 #6

P: n/a
Bob,

Good structuring your program is not only avoiding the Goto however as well
some other commands where it was by instance in Cobol the Alter which was
one of the options to continue on a different place again.

A lot of us think they should be banned from program languages.

Programmers who made non structured programs will always exist and therefore
these awfull commands are comming back in new languages where they first
where banned because those programmers are screaming for them because they
had them in past.

I would go for the code from Ken.

And when you cannot, look first for another classic awfull command, however
what is implemented in VBNet very good for structuring your program; the
Select. Case

Just my thought,

Cor

"eBob.com" <eB******@totallyfakeisp.com>
Thanks Ken. Yes. I meant to say in my post that I knew I could avoid
the GoTo by restructuring the If. And I suppose that even works in
general. BUT ... I am still wondering if there is some language
construct specifically for this. I also meant to say that I was
looking for the equivalent of the C/C++ continue statement.

But you would have mentioned the VB equivalent of the the C/C++
continue statement in your response, so I am gathering that VB does
not have such a construct. I guess I can live without it.

Thanks again, Bob

On Sun, 10 Oct 2004 19:11:54 -0400, "Ken Tucker [MVP]"
<vb***@bellsouth.net> wrote:
Hi,

What is wrong with this.
For Each Thing As OFI In FileInfo
If Thing.Displayed = True Then
If yada yada yada Then
TextBox2.Text = Thing.Name
End If
End If
Next Thing
Ken
-----------------------
"eBob.com" <eB******@totallyfakeisp.com> wrote in message
news:lk********************************@4ax.com. ..
How do you make a loop iterate early without using a GoTo? (I guess
I've done too much structured programming and I really don't like
using GoTos.)

Here's my code ...

For Each Thing As OFI In FileInfo
If Thing.Displayed <> True Then
GoTo Iterate 'skip this entry; try next one
End If

If yada yada yada Then
TextBox2.Text = Thing.Name
End If
Iterate:
Next Thing

I'm thinking that there has to be some way to do this without using
GoTo but I've not been able to find it.

Thanks, Bob

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.