doscode wrote:I don't understand your code, why you write it this way.
if !ThisIsLegalNumber! EQU 1 %and% not defined break
What does it mean? I think that it doesn't solve anything. Will this break the loop or not? Next code there.
OK. Let's be more clear about this matter.
If you have a FOR loop nested inside another one this way:
Code: Select all
rem Outer loop:
for %%D in (for-set) do (
some commands...
rem Inner loop:
for %%A in (for-set) do (
commands of inner loop...
)
more commands...
)
You may break the inner FOR this way:
Code: Select all
rem Outer loop:
for %%D in (for-set) do (
some commands...
rem Inner loop:
SET BREAK=
for %%A in (for-set) do (
IF NOT DEFINED BREAK (
commands of inner loop...
IF SOME_CONDITION SET BREAK=TRUE
) <- closing parentheses of new IF
) <- original closing parentheses of inner FOR
more commands...
)
You must pay attention to include ALL original commands of inner FOR inside the new IF.
In the
particular case when ALL commands of inner FOR are included in an IF that have not ELSE part this way:
Code: Select all
rem Outer loop:
for %%D in (for-set) do (
some commands...
rem Inner loop:
for %%A in (for-set) do ( <- there are NOT commands
if condition ( <- ... between previous FOR and this IF
commands of inner loop...
) <- there are NOT commands
) <- ... between closing IF and closing FOR
more commands...
)
... then you may use the same IF to control the break this way:
Code: Select all
rem Outer loop:
for %%D in (for-set) do (
some commands...
rem Inner loop:
SET BREAK=
for %%A in (for-set) do ( <- there are NOT commands
if condition IF NOT DEFINED BREAK ( <- ... between previous FOR and this IF
commands of inner loop...
IF SOME_CONDITION SET BREAK=TRUE
) <- there are NOT commands
) <- ... between closing IF and closing FOR
more commands...
)
This method is simpler than include an additional IF to control the break like in the first example, but can only be used in this particular case.
In this case, if you want to write ths command:
Code: Select all
if condition if not defined break (
... in a clearer way, you may use the trick to define SET AND=IF and then change it this way:
Code: Select all
if condition %and% not defined break (
... that, in my opinion, is clearer.
Antonio