syntax error

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
doscode
Posts: 174
Joined: 15 Feb 2012 14:02

syntax error

#1 Post by doscode » 30 May 2012 17:10

Can you help me with this?

Code: Select all

@echo off

FOR /F %%X IN (x/list.txt) DO (

REM echo %%X
SET /A odd="%%X%%2"

if %odd%==0 echo EVEN %%X
else Echo ODD %%X
  FOR /F %%Y IN (y/list.txt) DO (
  REM echo %%Y
  SET /A odd="%%Y%%2"
  if %odd%==0 echo EVEN %%X
  else Echo ODD %%X
)
)
pause


I cannot get the conditions working.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: syntax error

#2 Post by Fawers » 30 May 2012 17:19

Of course you can't:
Firstly, you need delayed expansion if you want to work with variable manipulation within loops.
Secondly, you didn't put the IF statements on the same line.

Code: Select all

@echo off
setlocal enableDelayedExpansion

FOR /F %%X IN (x/list.txt) DO (

REM echo %%X
SET /A "odd=%%X %% 2"

if "!odd!"=="0" (echo EVEN %%X
) else Echo ODD %%X
  FOR /F %%Y IN (y/list.txt) DO (
  REM echo %%Y
  SET /A "odd=%%Y %% 2"
  if "!odd!"=="0" (echo EVEN %%X
  ) else Echo ODD %%X
 )
)
pause

doscode
Posts: 174
Joined: 15 Feb 2012 14:02

Re: syntax error

#3 Post by doscode » 31 May 2012 00:12

Thanks. I forgot about it when I spend some time with different language.

Post Reply