?
Solved

How to break a DOS loop

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
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…
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…
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.

777 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