Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 465 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"continue" equivalent command in nested loop in Windows Batch

#1
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, 4, 8, 16, 32, 64, 128, 256) do (
if %%i gtr %%j goto CONTINUE
test.exe 0 %%i %%j 100000 > "%%i_%%j".txt
:CONTINUE
rem
)
)

But when `if` statement is true for the first time, it does not iterate further. I only get text files upto `1_256.txt`. So it seems that `goto CONTINUE` has a problem. What is wrong with my batch file?
Reply

#2
it seems what you are actually trying to accomplish is a poor man's "less or equal than".
In this case, why not use the real "less or equal than", which is `LEQ`?
Additionally, you seem to want the output of test.exe in the "%%i_%%j".txt file, so don't use `echo`.

So this would be

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 (
if %%i LEQ %%j test.exe 0 %%i %%j 100000 > "%%i_%%j".txt
)
)

Reply

#3
`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][refans] 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


[refans]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through