As jeb noted, the rest of the loop is skipped but evaluated, which makes the FOR
solution too slow for this purpose. An alternative:
set F=1
:nextpart
if not exist "%F%" goto :EOF
echo %F%
set /a F=%F%+1
goto nextpart
You might need to use delayed expansion and call
subroutines when using this in loops.