When running the following batch file I would expect the program to return from the func routine and display the 'end program' message. Instead, the program seems to hang when pressing a key after the pause command is executed in the for loop. Replacing exit /b with goto :eof seems to have the same effect.
@echo off
echo start program
call :func
echo end program
pause
exit /b
:func
echo start func
for /l %%l in () do (
echo start loop
pause
exit /b
echo end loop
)
echo end func
exit /b
Expected output:
start program
start func
start loop
Press any key to continue...
end program
Press any key to continue...
I would like to avoid using goto-label as an infinite loop. With the following loop, the iteration message is only displayed once:
:test
for /l %%l in (1,1,3) do (
echo iteration: %%l
exit /b
)
exit /b
What would be the appropriate way to use an infinite loop inside a routine and still be able to return to the caller?