A really infinite loop, counting from 1 to 10 with increment of 0.
You need infinite or more increments to reach the 10.
You can also use the short form: for ... in () do
for /L %%n in (1,0,10) do (
echo do stuff
rem ** can't be leaved with a goto (hangs)
rem ** can't be stopped with exit /b (hangs)
rem ** can be stopped with exit
rem ** can be stopped with a syntax error
call :stop
)
:stop
call :__stop 2>nul
:__stop
() creates a syntax error, quits the batch
This could be useful if you need a really infinite loop, as it is much faster than a goto :loop version because a for-loop is cached completely once at startup.
** pseudo infinite **
If you need a loop that is fast (then you shouldn't use GOTO), but the loop should be breakable, it's possible to use nested loops.
@echo off
setlocal EnableDelayedExpansion
set cnt=0
REM *** 6 nested loops, each count from 0 to 255
for /L %%L in (0 1 255) do for /L %%L in (0 1 255) do for /L %%L in (0 1 255) do for /L %%L in (0 1 255) do for /L %%L in (0 1 255) do for /L %%L in (0 1 255) do (
set /a cnt+=1
echo Loop !cnt!
if !cnt! == 10 goto :break
)
:break
It loops 2⁴⁸ (=281474976710656) times, but if the goto breaks the loops, it needs a maximum of 1536 empty loops.
For CommandOr Link