Solved

How to break a DOS loop

Posted on 2009-05-13
3
2,054 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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.

772 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

16 Experts available now in Live!

Get 1:1 Help Now