Solved

How to break a DOS loop

Posted on 2009-05-13
3
2,056 Views
Last Modified: 2013-11-29
Experts, can you show me how to break a loop in DOS? I tried to break the loop with aSTATUS flag, but it continues to run until 10.
setlocal enabledelayedexpansion
 

set aSTATUS=

for /L %%c IN (1, 1, 10) do (

  set aSTATUS=STOP

@echo counter=%%c

  if "%aSTATUS%" == "STOP" ( GOTO :EOF )

)

Open in new window

0
Comment
Question by:jl66
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 300 total points
ID: 24378125
Replace %aSTATUS% with !aSTATUS! since you're using it inside a FOR loop.
0
 
LVL 2

Assisted Solution

by:Gregdo
Gregdo earned 20 total points
ID: 24378852
If this is your complete code, you are missing the :EOF tag that GOTO is looking for.  See the last line of the code below.
setlocal enabledelayedexpansion

 

set aSTATUS=

for /L %%c IN (1, 1, 10) do (

  set aSTATUS=STOP

@echo counter=%%c

  if "%aSTATUS%" == "STOP" ( GOTO :EOF )

)

:EOF

Open in new window

0
 
LVL 21

Assisted Solution

by:AmazingTech
AmazingTech earned 180 total points
ID: 24379262
If your only defining it to break it out. I would just use if defined. Once you define the variable aSTATUS it will break out.
set aSTATUS=

for /L %%c IN (1, 1, 10) do (

  set aSTATUS=STOP

@echo counter=%%c

  if defined aSTATUS GOTO :EOF

)

Open in new window

0

Featured Post

Being driven mad by email signature updates?

Having to make a change to your users’ email signatures, yet again? Feel like your head is going to explode? Rely on an Exclaimer email signature management solution to make the process simple!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
For loop to add numbers 3 59
pdf convertor 7 64
Copy dir and files with robocopy 2 30
program for opening files (like explorer) 4 25
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

929 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

8 Experts available now in Live!

Get 1:1 Help Now