Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Change Do/Loop to break then continue after so many iterations?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed from AZ - 27 Jun 2007 19:12 GMT
Right now my code is set up to run a Do/Loop until all iterations are
completed, then execute more code.  I have realized that if the number
of iterations is very large, I will need to break things up into
smaller chunks.  If the total iteratins is 100, for instance, I wiil
need to run the loop 20 times, execute the code, loop 20 more,
execute, etc etc.  For some reason, I can't seem to get my brain
moving on this.  A drop-kick in the right direction would be
appreciated.

I currently have:

y = Total_Iterations
x = 1

Do
 ' Some_code
 x = x + 1
Loop Until x = y

' Execute_this

I need to change to:

y = Total_Iterations
x = 1

If y > 20

Do
 ' Some_code
 x = x + 1
Loop Until x = 20

' Execute_this

' Go back for 20 more and execute again
' until y has been reached.

Ed
Klaus Linke - 28 Jun 2007 03:12 GMT
Hi Ed,

You could use the Mod operator to run some code every 20th iteration:

y = Total_Iterations
x = 1

Do
   Some_code
   If (x mod 20) = 0 then
       Execute_this
   Endif
   x = x + 1
Loop Until x = y

Regards,
Klaus
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.