473,386 Members | 1,706 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,386 software developers and data experts.

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 2675
* Terry Olsen <to******@hotmail.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**********@planet.nl> wrote in message
news:ea**************@TK2MSFTNGP12.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******@hotmail.com> wrote in message
news:OQ*************@TK2MSFTNGP09.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******@hotmail.com> wrote in message
news:uS**************@TK2MSFTNGP10.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******@hotmail.com> wrote in message
news:uS**************@TK2MSFTNGP10.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**********@planet.nl> wrote in message
news:ea**************@TK2MSFTNGP12.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
"WriteLineToFile", but having the code inline seems waaaay faster...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Od**************@TK2MSFTNGP10.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******@hotmail.com> wrote in message
news:uS**************@TK2MSFTNGP10.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**********@planet.nl> wrote in message
news:ea**************@TK2MSFTNGP12.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.Threading.ThreadPool.QueueUserWorkItem 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******@hotmail.com> wrote in message
news:uV**************@TK2MSFTNGP12.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
"WriteLineToFile", but having the code inline seems waaaay faster...
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:Od**************@TK2MSFTNGP10.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******@hotmail.com> wrote in message
news:uS**************@TK2MSFTNGP10.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**********@planet.nl> wrote in message
news:ea**************@TK2MSFTNGP12.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
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...
5
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...
8
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...
2
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...
4
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...
13
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
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...
0
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.