473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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

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
6 3628
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: deko | last post by:
I have a logging routine that's supposed to silently log errors caught by error handler code on certain functions. The problem is sometimes stuff happens and the error handler can get caught in a...
18
by: Ken Varn | last post by:
Is there any way to reset a foreach loop to re-iterate through the collection as if it were starting from the beginning? Namely, if I delete an item out of a collection, I want to be able to reset...
8
by: Terry Olsen | last post by:
How do I loop back to the beginning of a for/next loop before getting to the end of it? Isn't there an "iterate" command or something like that? For Each This in That ...code if This = False...
8
by: Microsoft | last post by:
I have the following loop the length contains somewhere around 1000+ items: For elemIndex = 0 To len - 1 elem = CType(doc.all.item(elemIndex), mshtml.IHTMLElement) If elem.tagName = "A" Then If...
23
by: Mitchell Vincent | last post by:
Is there any way to "skip" iterations in a for loop? Example : for x = 1 to 10 if something = 1 next endif
32
by: cj | last post by:
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...
8
by: Jim Langston | last post by:
There's the thing about iterating though a map or vector when you may delete one of the elements, where you simply assign the iterator to the map.erase() statement or increment it if you don't. ...
26
by: Alexander Korsunsky | last post by:
Hi! I have some code that looks similar to this: -------------------------------------------- char array = "abcdefghij"; for (int i = 0; i < 10; i++) {
44
by: James Watt | last post by:
can anyone tell me how to do an infinite loop in C/C++, please ? this is not a homework question .
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.