Nested for loop/ for loop inside for loop in Batch File Programming

preview_player
Показать описание
Hi friends,
Here we have discussed about how to use a for loop inside a for loop ie. nested For loop and the syntax is
FOR %%A IN (set) DO FOR %%B IN (set) DO Command

examples:
@echo off
FOR %%A IN (1 2 3) DO FOR %%B IN (A B C) DO ECHO %%A%%B
pause

@Echo Off
Setlocal
For %%A in (1 2) DO (
Echo Outer loop %%A
call :inner
)
pause
goto :eof

:inner
For %%B in (A B) DO (
echo Inner loop Outer=%%A Inner=%%B
)
Previous for loop links
Please subscribe and stay tuned for more technology updates. Thank you
Рекомендации по теме
Комментарии
Автор

Superb boss u solved my nested loop issue

alpeshrr
Автор

short video, but very helpful. more please, thank you +++

tabatali
Автор

public static void printStars(int n)
{
int i, j;

// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{

// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing stars
System.out.print("* ");
}

// ending line after each row
System.out.println();
}
}






how do you do standard nested for loops that you can do easily in every other language, the internet has no examples of these types of nested for loops using batch scripting, I cannot believe it.

lemondevil
Автор

Hi I need some help on the for /f loop.. with dir listing the files in a particular directory ..this is related to delayed expansion. Even when I use delayed expansion as soon as use echo it skips to the next file.. rather than staying at the same file ... how can I make the counter stay at the first file in round one and then to the second file in round two..

w
Автор

Dear Sir
I am dealing with a for /f command. I wondering if you could help me. I can share my code with you is very simple.
Best regards

miguelsomma