Solved

How to break a DOS loop

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

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

Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

730 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