Breaking out of for loop in batch file when using goto
<p>I need to run a program for each line in a file. I am triggering four instances at a time. After four instances, waiting for some time and triggering another one. After wait time batch script is breaking.</p>

<p>Please suggest if I'm doing wrong. </p>

<pre><code>for /F "tokens=*" %%J in ( %JobListFile% ) do (
    SET JobName=%%J
    echo job name !JobName!

    if "!JobName!" equ "" (
        echo joblist not found... rerun the script..
        REM exit /b
    ) else (
        :waittofinish
        for /F "tokens=*" %%a in ( 'tasklist /fi "IMAGENAME eq dsexport.exe" ^| grep -c "dsexport.exe"' ) do ( SET /A CurrInstances=%%a )
        echo current instance is !CurrInstances!
        echo parallelism set to !NoOfParallelInstances!
        if "!CurrInstances!" gtr "!NoOfParallelInstances!" (
            echo going to wait
            sleep 5
            goto waittofinish
            echo failed to go wait label...
        ) else (
            echo Exporting job:   !JobName! ...............Starting
            start /b cmd /C "C:/IBM/9.1/InformationServer/Clients/Classic/dsexport.exe /D=%vDomain% /U=%vuserID% /P=%vpassword% /H=%vServer% %vDSProject% /NODEPENDENTS /JOB=!JobName! %tmppath%\!JobName!.dsx"
            echo.
            echo.
        )
    )

)

echo script completed...

exit /b
</code></pre>