?
Solved

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

Posted on 2003-10-22
3
Medium Priority
?
553 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
LeeTutor earned 400 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When asking a question in a forum or creating documentation, screenshots are vital tools that can convey a lot more information and save you and your reader a lot of time
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

801 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