Solved

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

Posted on 2003-10-22
3
552 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 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

705 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