1

It won't work :(

setlocal enabledelayedexpansion
SET ENR[1]=12345
SET ENR[2]=12345
SET ENR[3]=99999
SET ENR[4]=45678
SET /a Count=4

REM marking doubles from array
SET /a Help1=%Count%-1
FOR /L %%i in (1,1,%Help1%) do (
    SET /a Help2=%Count%-%%i
    FOR /L %%a in (1,1,!Help2!) do (
        IF !ENR[%%i]!==!ENR[%%i+%%a]! SET ENR[%%i]="double"
    ) 

How can I make !ENR[%%i+%%a]! work? Of coure I want the computer to calculate %%i+%%a before expanding the variable.

mifu
  • 33
  • 1
  • 5
  • 3
    You have to calculate %%i+%%a outside of the if statement because batch can't do math without a `set /a` command. – SomethingDark Apr 12 '17 at 15:32
  • 2
    For example: `set /A j=%%i+%%a` and then use `FOR %%j in (!j!) DO IF !ENR[%%i]!==!ENR[%%j]! SET ENR[%%i]="double"`. This management is fully explained at [this answer](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Apr 12 '17 at 16:05
  • I opted for the goto option. Thank you anyways! – mifu Apr 13 '17 at 00:26

1 Answers1

0
setlocal enabledelayedexpansion
SET ENR[1]=12345
SET ENR[2]=12345
SET ENR[3]=99999
SET ENR[4]=45678
SET /a Count=4

SET /a x=0
:loop
SET /a x+=1
SET /a y=0
:subloop
SET /a y+=1
IF %x% NEQ %y% (IF !ENR[%x%]!==!ENR[%y%]! (SET ENR[%x%]="double"))
IF %y% NEQ %Count% goto :subloop
IF %x% NEQ %Count% goto :loop
mifu
  • 33
  • 1
  • 5