- 1 year ago
Multiple For Loops in Batch Script on same Content
In a batch script, you can use multiple FOR
loops to iterate over the same content in different ways. Here's an example to illustrate the concept:
batch@echo off
setlocal
rem Sample content
set "content=1 2 3 4 5"
rem First FOR loop to iterate over the content
for %%a in (%content%) do (
echo First loop: %%a
rem Second FOR loop to iterate over the content again
for %%b in (%content%) do (
echo Second loop: %%b
)
)
endlocal
In this example, we have a variable named content
with a space-separated list of values. We use the first FOR
loop (%%a
) to iterate over the content and print each value. Within this loop, we have a second FOR
loop (%%b
) that also iterates over the content and prints each value.
When running the script, each value of content
will be printed by the first loop, and for each iteration of the first loop, the second loop will run and print each value again. This allows you to perform different actions or operations within each loop iteration while iterating over the same content.
You can customize the code within each loop to perform specific operations based on your requirements.