473,748 Members | 2,161 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3650
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******@total lyfakeisp.com> wrote in message
news:lk******** *************** *********@4ax.c om...
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***@bellsout h.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******@total lyfakeisp.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...Els e statement, and transfers
control to the statement immediately following Next.

-L
"eBob.com" <eB******@total lyfakeisp.com> wrote in message
news:lk******** *************** *********@4ax.c om...
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******@total lyfakeisp.com> wrote in message
news:pe******** *************** *********@4ax.c om...
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***@bellsout h.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******@total lyfakeisp.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...Els e statement, and transfers
control to the statement immediately following Next.

-L
"eBob.com" <eB******@total lyfakeisp.com> wrote in message
news:lk******** *************** *********@4ax.c om...
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******@total lyfakeisp.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***@bellsout h.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******@total lyfakeisp.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
15956
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 loop. Is there some way to send a break from VBA code to break out of the loop? Here's what the error handler code looks like: Private Function MyFunction On Error GoTo HandleErr
18
6643
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 the loop. -- ----------------------------------- Ken Varn Senior Software Engineer Diebold Inc.
8
2692
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 Then (start loop over with next This) ...code Next *** Sent via Developersdex http://www.developersdex.com ***
8
1689
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 elem.innerText = "1." Then elem.click() End If End If Next elemIndex
23
22002
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
2598
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 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?
8
2143
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. Well, I have this issue where I may delete the map element in 3 different places: for ( map_key_pcmissile::iterator mit = World.Missiles.begin(); mit != World.Missiles.end(); ) { if ( /* Some Condition */ )
26
10213
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
4320
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
8983
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8822
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9528
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, 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...
0
9359
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9236
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 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...
1
6792
isladogs
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...
0
4863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3298
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
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.