“continue” equivalent command in nested loop in Windows Batch

前端 未结 2 1651
忘了有多久
忘了有多久 2021-02-08 20:20

I have a batch file which contains nested loop with continue-like command:

for %%i in (1, 2, 4, 8, 16, 32, 64, 128, 256) do (
    for %%j in (1, 2,          


        
2条回答
  •  旧巷少年郎
    2021-02-08 20:57

    goto :Label inside of a block of code () like a for loop breaks the block context, so everything after the :Label is treated as being outside of the block. So you need to invert the if condition to not need goto as ths's answer demonstrates, or you place the code fragment with goto and :Label into a subroutine and use call like this:

    for %%i in (1, 2, 4, 8, 16, 32, 64, 128, 256) do (
        for %%j in (1, 2, 4, 8, 16, 32, 64, 128, 256) do (
            call :SUB %%i %%j
        )
    )
    exit /B
    
    :SUB outer inner
    if %1 gtr %2 goto CONTINUE
    test.exe 0 %1 %2 100000 > "%1_%2.txt"
    :CONTINUE
    rem
    exit /B
    

提交回复
热议问题