?
Solved

How to break a DOS loop

Posted on 2009-05-13
3
Medium Priority
?
2,074 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
[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
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Know the reasons and solutions to move/import EDB to New Exchange Server. Also, find out how to recover an Exchange .edb file and to restore the file 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…
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). …

649 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