473,549 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

For Next loop & looping early

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 ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
8 2684
* Terry Olsen <to******@hotma il.com> scripsit:
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?


Not in VB.NET 2003. You will have to use a label + 'GoTo', or prevent a
block inside the loop from being executed using 'If...Then'. In VB
2005, 'Continue' is available.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
Terry,

What do I miss?

For Each This in That
if This = True Then
...code
End if
Next

Works like a charm, with the exception when you try to delete a This in that
code.

I hope this helps?

Cor
Nov 21 '05 #3
Yeah that works...I just didn't want to put about 50 lines of code inside a
block if statement.
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl...
Terry,

What do I miss?

For Each This in That
if This = True Then
...code
End if
Next

Works like a charm, with the exception when you try to delete a This in that code.

I hope this helps?

Cor

Nov 21 '05 #4
You can use a try/end try block. Then use exit try to goto the next loop.
Frank

"Terry Olsen" <to******@hotma il.com> wrote in message
news:OQ******** *****@TK2MSFTNG P09.phx.gbl...
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 ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #5

"Terry Olsen" <to******@hotma il.com> wrote in message
news:uS******** ******@TK2MSFTN GP10.phx.gbl...
Yeah that works...I just didn't want to put about 50 lines of code inside a block if statement.


There's nothing wrong with that. I have no problem using GoTo in this case
because VB has always lacked a Continue statement (wait a year!), but I only
use it in cases where I'm in a deeply nested loop and only one convoluted
condition requires me to iterate immediately. Otherwise I kinda feel
dirty....
Nov 21 '05 #6
Terry,
50 lines sounds like you need a new method! :-|

I would put the 50 lines in its own method (Sub or Function) then the For
Each can have a simply If that simply calls the method.

Then again I tend to follow OO with smaller objects with smaller methods...

Hope this helps
Jay
"Terry Olsen" <to******@hotma il.com> wrote in message
news:uS******** ******@TK2MSFTN GP10.phx.gbl...
Yeah that works...I just didn't want to put about 50 lines of code inside a block if statement.
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl...
Terry,

What do I miss?

For Each This in That
if This = True Then
...code
End if
Next

Works like a charm, with the exception when you try to delete a This in

that
code.

I hope this helps?

Cor


Nov 21 '05 #7
What's the largest method you have coded? Believe me, I've split up my
program into Mods & Functions & Methods. But it seems as though I'm slowing
it down quite a bit with all the "jumping around". The meat of the program
is a loop. It goes out to about 30 servers (some on 56k and some on 128k so
threading wouldn't help me here), downloads 30-100 log files from each
server (after telling the server to zip them up), then it unzips & parses
all those files to create an html page that displays the data from the logs
in an easily readable format. I tried having a method called
"WriteLineToFil e", but having the code inline seems waaaay faster...
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:Od******** ******@TK2MSFTN GP10.phx.gbl...
Terry,
50 lines sounds like you need a new method! :-|

I would put the 50 lines in its own method (Sub or Function) then the For
Each can have a simply If that simply calls the method.

Then again I tend to follow OO with smaller objects with smaller methods...
Hope this helps
Jay
"Terry Olsen" <to******@hotma il.com> wrote in message
news:uS******** ******@TK2MSFTN GP10.phx.gbl...
Yeah that works...I just didn't want to put about 50 lines of code inside
a
block if statement.
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl...
Terry,

What do I miss?

For Each This in That
if This = True Then
...code
End if
Next

Works like a charm, with the exception when you try to delete a This

in that
code.

I hope this helps?

Cor



Nov 21 '05 #8
Terry,
What's the largest method you have coded? Does it really matter? Size doesn't really matter here, the point I was
making is that the "length" of your method is really in the second method,
the first method is simply the loop & possibly the if. The second method has
all the code for the loop itself, allowing the second method to use Exit Sub
to go to the top (bottom really) of the loop...
But it seems as though I'm slowing
it down quite a bit with all the "jumping around". Define "seems", I would use CLR Profiler or other profiling techniques to
actually time the loop & subroutines to see how will it performs or not
performs.

Remember the 80/20 rule (link below) that is 80% of the execution time of
your program is spent in 20% of your code. I will optimize (worry about
performance) the 20% once that 20% has been identified & proven to be a
performance problem via profiling (CLR Profiler is one profiling tool).
It goes out to about 30 servers (some on 56k and some on 128k)
downloads 30-100 log files from each
server (after telling the server to zip them up), then it unzips & parses
all those files to create an html page that displays the data from the logs
Sounds like the ideal candidate for multi-threading!

As I would expect there is a lag connecting to each server, plus a lag
having each server zip its files, then another lag in downloading the files.
If you save the html pages to disk, there would be a lag there.
Multi-threading would allow your processor to work on another request while
its waiting for the lag...

I would define the routine that processed a single server as a subroutine, I
would then use System.Threadin g.ThreadPool.Qu eueUserWorkItem to queue each
request, to this subroutine. Where the Request includes a "State" object
with the server to process & other request specific info. This way a couple
of 128K servers will finish for each 56K server

Unless of course you have a single modem that is dialing each server, then I
would single thread the "download" part & consider multi-threading the unzip
& parse part...
For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Hope this helps
Jay

"Terry Olsen" <to******@hotma il.com> wrote in message
news:uV******** ******@TK2MSFTN GP12.phx.gbl... What's the largest method you have coded? Believe me, I've split up my
program into Mods & Functions & Methods. But it seems as though I'm slowing it down quite a bit with all the "jumping around". The meat of the program is a loop. It goes out to about 30 servers (some on 56k and some on 128k so threading wouldn't help me here), downloads 30-100 log files from each
server (after telling the server to zip them up), then it unzips & parses
all those files to create an html page that displays the data from the logs in an easily readable format. I tried having a method called
"WriteLineToFil e", but having the code inline seems waaaay faster...
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:Od******** ******@TK2MSFTN GP10.phx.gbl...
Terry,
50 lines sounds like you need a new method! :-|

I would put the 50 lines in its own method (Sub or Function) then the For
Each can have a simply If that simply calls the method.

Then again I tend to follow OO with smaller objects with smaller

methods...

Hope this helps
Jay
"Terry Olsen" <to******@hotma il.com> wrote in message
news:uS******** ******@TK2MSFTN GP10.phx.gbl...
Yeah that works...I just didn't want to put about 50 lines of code

inside
a
block if statement.
"Cor Ligthert" <no**********@p lanet.nl> wrote in message
news:ea******** ******@TK2MSFTN GP12.phx.gbl...
> Terry,
>
> What do I miss?
>
> For Each This in That
> if This = True Then
> ...code
> End if
> Next
>
> Works like a charm, with the exception when you try to delete a This

in that
> code.
>
> I hope this helps?
>
> Cor
>
>



Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
4284
by: Psybar Phreak | last post by:
hi all i have an array of Process objects, each elements has an id (process.id), and arrival time (process.at), processing time (process.pt) and a boolean indicating whether the process has completed (process.done). atm, i have a loop that i going through the elements and check whether each elements has been done, i am now at a point in...
5
6313
by: Petr Bravenec | last post by:
I have found that when I use the RETURN NEXT command in recursive function, not all records are returned. The only records I can obtain from function are records from the highest level of recursion. Does exist some work-around? Thanks Petr Bravenec example: create table foo (
8
7578
by: Shamrokk | last post by:
My application has a loop that needs to run every 2 seconds or so. To acomplish this I used... "Thread.Sleep(2000);" When I run the program it runs fine. Once I press the button that starts the looping function the window becomes unmovable and cannot close under its own direction (the upper right "close 'X'") My first attempt to solve...
2
1721
by: Sparky Arbuckle | last post by:
Hello All! My problem is trying to calculate SubTotal in my FOR EACH NEXT Loop. I am looping through depending on how many of each different item is in the user's shopping cart. I am using each Item ID in the cart to display the appropriate image, artist name, and price information for each item in the cart. I am running into problems when I...
4
1157
by: Slonocode | last post by:
For some reason my for/next loop is not looping. The original if statement is satisfied as ForecastDays = 5. When i = 0 the first Case 0 block fires and i is set to 1. But it never loops back to the top of the for loop. If ForecastDays > 0 And ForecastDays < 6 Then Dim i As Int16 = 0 For i = 0 To i = ForecastDays - 1 Select Case i
13
14709
by: Joseph Garvin | last post by:
When I first came to Python I did a lot of C style loops like this: for i in range(len(myarray)): print myarray Obviously the more pythonic way is: for i in my array: print i
3
1807
by: Dale | last post by:
Access 2000 I am trying to check the form to be sure that required fields are entered. For each required field (Control) I have set the tag property to "1". I am trying to loop through all controls with a tag property of "1", If they are null, I want to stop the loop and setfocus on the control. The below code works Except it will not...
0
24161
ADezii
by: ADezii | last post by:
If you want to visit each item in an Array, you have two alternatives: Use a For Each..Next loop, using a Variant to retrieve each value in turn. Use a For...Next loop, looping from the Lower Bound to the Upper Bound of the Array. For Each...Next seems simpler because you need not worry about retrieving the Lower and Upper Bounds- the...
1
3863
colinod
by: colinod | last post by:
Hi everyone i am trying to make a page that goes to the next recorset when i click on a button so the page only shows one record at a time, this is for updating so i need to be able to go to the next recodset from the page that updates the database also. the code for the page that i have which lists all the records is as follows ...
0
7457
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...
1
7483
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7817
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...
0
6051
agi2029
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...
0
5092
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...
0
3504
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...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
771
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...

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.