Exit form inner loop in bat file

March 9, 2012 at 04:26:44
Specs: Windows 7

With the code below, I am trying to do a while loop inside a FOR loop. The while loop should be executed until the condition is met and then come back to the FOR loop.
It seems that although the code in the outer FOR loop is not executed, its counter goes further and when the condition is met the FOR loop is finished instantly.

What I would like to achieve is that the outer FOR loop is paused until the inner one is running and when the inner is finished/stopped then the FOR continues?

I will appreciate any hints.

This is the code:

@ECHO off
setlocal EnableDelayedExpansion

FOR %%I IN (1 2 5 6 9 ) DO (

cd %%I

call some_bat_file rem this bat file return %chk% with value of 1 or 2


if !chk! EQU 2 start some_program
if !corechk! EQU 1 GOTO :BEGIN

cd ..



See More: Exit form inner loop in bat file

Report •

March 15, 2012 at 07:09:01
my thinking is that if the !chk! EQU 1, you are going to be in an infinite loop? seems kinda odd to do things that way?

also should only have one :BEGIN, makes this confusing.

are you trying to loop through directories? thats what the cd makes me think.

theoretically if you call another batch as it looks like you are doing, it would go through that then return to the program and continue.


Report •
Related Solutions

Ask Question