1

I am trying to implement multiple for loop in batch like:

for x=1:10 
for y=x+1:10
//my code
end
end

My code is:

@echo off
for /l %%x in (1,1,10) do (
 for /l %%y in (%%y+1,1,10) do (
  //my code
 )
)

However, it doesn't work. Can anyone help me? Thanks.

2
  • 3
    Try changing %%y+1,1,10 to %%x+1,1,10 Commented Apr 17, 2014 at 6:04
  • 1
    @Dale - will not work , in batch you cannot do math in for definition. Commented Apr 17, 2014 at 6:33

3 Answers 3

2

I'm reposting a solution but in a simpler script.

@echo off
setlocal enableDelayedExpansion
for /l %%x in (1,1,10) do (
 set /a inner=%%x+1
    for /l %%y in (!inner!,1,10) do ( 
     echo %%x, %%y
    )
)
endlocal
pause
Sign up to request clarification or add additional context in comments.

Comments

0
@echo off
for /l %%x in (1,1,10) do (
 echo #LOOP [1] ITERATION [%%x]
 for /l %%y in (1,1,10) do (
 echo  ##LOOP [2] ITERATION [%%y]
 )
echo.
)

1 Comment

As far as I understand the question the OP want the inner loop to start from %%x+1 ...
0
@echo off
setlocal enableDelayedExpansion
for /l %%x in (1;,;1step;,;10#=101) do (
 set /a inner=%%x+1

 @@echo ###%%x is from outer loop###

 for /l %%y in (,,,!inner!==1@==10times,9) do ( 

  @@echo -----%%y is from inner loop

 )
)
endlocal

Simplified

@echo off
setlocal enableDelayedExpansion
for /l %%x in (1;1;10) do (
 set /a inner=%%x+1

 echo - %%x is produced from outer loop

 for /l %%y in (!inner!;1;10) do ( 

 echo --- %%y is produced from inner loop

 )
)

2 Comments

No offense meant, but is there a reason you wrote it like that? That is incredibly difficult to read, and a newbie will have no hope to understand the points you have made.
@foxidrive - you're right - I should keep it more simple.Sometimes I tend to show a strange sense of humor...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.