Solved batch file for loop problem

December 28, 2014 at 06:22:48
Specs: windows 7
I have to add twO FOR LOOP'S values continously and to print that.but that shows operand missing.
eg: set a/ c=%%G-%%N
echo %c%
pause

See More: batch file for loop problem

Report •

✔ Best Answer
December 29, 2014 at 07:19:14
::======  script starts here  ===============
:: 
:: 048.bat  2014-12-29 20:17:58.03
@echo off & setLocal enableDELAYedeXpansioN
if exist *.TXT del *.TXT

set/a N=0
set/a X=N+4

for /L %%a in (0 4 16)    do (
for /L %%i in (!N! 1 !X!) do (
echo.%%i
) >> %%a.TXT
set/a N+=5
set/a X=N+4
)
::======  script ends here  =================
29 December 2014 22:18

=====================
M2 Golden-Triangle



#1
December 28, 2014 at 06:29:12
Post a useful chunk of your code. If it's 9 pages long gibe us a break and don't post the whole thing.

message edited by Mechanix2Go


Report •

#2
December 28, 2014 at 06:49:28
actually I have to create a text named 4.txt and that should contains till 4.ie
0
1
3
4.
the 5 to 9 should be saved in another file named 9.txt.
so I used two for loops
the program is

echo off
:LOOP1
for /L %%P IN (0,4,100) DO (ECHO.*>%%P.TXT
for /L %%G IN (0,1,100) DO (GOTO:SUB
:SUB
set /p A=%%G
set /p B=%%B
SET /A C=A-B
ECHO %C%
IF %C% GEQ 0 GOTO:CHECK4
:CHECK4
IF NOT %C% EQU 4 GOTO:LOOP2
GOTO:LOOP1

message edited by RAJESHJESHAR


Report •

#3
December 28, 2014 at 07:52:39
If you set vars here:

set /p A=%%G
set /p B=%%B

which are not useable by

SET /A C=A-B

that may account for the missing operand.
=====================================
This bit doesn't seem to do anything:
echo off
:LOOP1
for /L %%P IN (0,4,100) DO (ECHO.*>%%P.TXT
============================================

=====================
M2 Golden-Triangle


Report •

Related Solutions

#4
December 28, 2014 at 19:42:50
oh thanks bro but is there any way to add two for loops simply like
for /L %%P IN (0,4,100) DO (
for /L %%G IN (0,1,100) DO (
set /p A=%%Gset /p B=%%P
set /p C=A-B
ECHO %C%)
)

message edited by RAJESHJESHAR


Report •

#5
December 28, 2014 at 22:39:20
It might help to say what this is trying to do.

=====================
M2 Golden-Triangle


Report •

#6
December 28, 2014 at 23:41:41
the main concept is print 0 to 4 in a file named 0.txt
5-9 in 4.txt
10-14 in 8.txt
continuously.

problem is to detect only till 4 is only printed .and the next file (4.txt)shouldn't
contain 0 to 4.it should start only from 5 and ends with9.(5-9)
the next file (8.txt)should start containing from 10 to 14.


this is my program concept please help


Report •

#7
December 29, 2014 at 07:19:14
✔ Best Answer
::======  script starts here  ===============
:: 
:: 048.bat  2014-12-29 20:17:58.03
@echo off & setLocal enableDELAYedeXpansioN
if exist *.TXT del *.TXT

set/a N=0
set/a X=N+4

for /L %%a in (0 4 16)    do (
for /L %%i in (!N! 1 !X!) do (
echo.%%i
) >> %%a.TXT
set/a N+=5
set/a X=N+4
)
::======  script ends here  =================
29 December 2014 22:18

=====================
M2 Golden-Triangle


Report •

#8
December 29, 2014 at 08:00:53
oh thank you so much brother.its working brother. you are great

Report •

Ask Question