Solved

How to have batch file repeats two or more lines for "x" times?

Posted on 2003-10-22
3
544 Views
Last Modified: 2013-12-29
Is there a way I can repeat two or more lines of a batch file in
Win98SE without retyping the same code?

0
Comment
Question by:happycat
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
LeeTutor earned 100 total points
ID: 9600240
You can program loops in batch files, like so:

:Toploop

(statements to repeat go here)
goto Toploop

Unfortunately this sort of thing is an "infinite" loop (repeating until you use the Ctrl-C key combination to exit it) unless you have some sort of test for when to exit the loop before the "goto" statement.

Back in 1988, Pc Magazine published a book called "Pc Magazine DOS Power Tools Techniques, Tricks and Utilities", by Paul Somerson, that included a floppy disk with many assembly language routines to enhance DOS, including a program called LOOP.COM which incremented a counter that the IF ERRORLEVEL batch statement can test.  So, say you wanted to have a loop execute 15 times.  It would look like this:

Loop /s
:Toploop

(statements to repeat go here)
Loop
if not errorlevel 15 goto Toploop

The first "Loop /s" statement must be above the loop, to initialize the count to zero. The Loop statement within the loop just increments the count.

There are many other useful utilities written about in this book, too.  Where can you get it?  I found one place, where apparently you can buy this 1274 page book (!) for only 50 cents, used.  Unfortunately, the floppy disk that the utilities come on are on the old 5 1/4" floppy, not today's 3 1/2" floppy.  Maybe you can find an old computer that uses that sort of floppy drive as well as the smaller and then copy from one to the other.  Or, I could send you a copy of the program in an attachment if you put your email address in your profile.

http://www.amazon.com/exec/obidos/search-handle-url/index%3Dbooks%26field-keywords%3Ddos%252520power%252520tools%26store-name%3Dbooks/104-7162452-4822318
0
 

Author Comment

by:happycat
ID: 9601158
Thanks. I just figured out the goto command and how to label a line.
Yes it is infinite loop so your other comments are very helpful. Very well written.


0
 

Author Comment

by:happycat
ID: 9601170
LeeTutor, if you will that attachment would be great. Check profile for email, Thanks.
0

Featured Post

The curse of the end user strikes again      

You’ve updated all your end user’s email signatures. Hooray! But guess what? They’re playing around with the HTML, adding stupid taglines and ruining the imagery. Find out how you can save your signatures from end users today.

Join & Write a Comment

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now