How to use goto in nested loop in .bat script window

74 Views Asked by At

I'm a newbie, I don't really understand how to use goto. I have a small piece of code below. Why does the outer loop only run once?

@echo off
setlocal enabledelayedexpansion

for /L %%i in (1,1,3) do (
    echo parent loop no: %%i
    set "jump=0"
    for /L %%j in (1,1,5) do (
        echo child loop no: %%j
        if %%j equ 2 (
            set "jump=1"
            goto :jump_label
        )
    )
    :jump_label
    echo test
)
pause

The result I received is as below:

parent loop no: 1
child loop no: 1
child loop no: 2
test

Expect result:

parent loop no: 1
child loop no: 1
child loop no: 2
parent loop no: 2
child loop no: 1
child loop no: 2
parent loop no: 3
child loop no: 1
child loop no: 2
test

Please help!

0

There are 0 best solutions below