刚开始接触批处理,感觉批处理就是字符串的替换,set /a能把数字字符串作为整形处理。
试了试call [标签] 的参数传递
@echo off
setlocal EnableDelayedExpansion
for /l %%i in (2 1 1000) do (
call :prime %%i flag
if "!flag!"=="true" set /p "=%%i " < nul
)
goto :end
:prime number res
setlocal EnableExtensions
set /a n=%1/2
for /l %%j in (2 1 !n!) do (
set /a var=%1%%%%j
if !var! EQU 0 endlocal & set %2=false & goto :end
)
endlocal & set "%2=true" & goto :end
:end
rem 不用goto :eof,添加调试语句