[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How to break a DOS loop

Posted on 2009-05-13
3
Medium Priority
?
2,076 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 1200 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 80 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 720 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this modest contribution, I want to share with the IT community (especially system administrators, IT Support Engineers and IT Help Desks) about Windows crashes/hangs and how to deal with these particular problems.
Most folks would know the basics of how Dropbox works, so that’s not the purpose of this article. Security is what it’s all about, so here I’ll share how I choose to secure my Dropbox Account and the Data it contains.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

829 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