I am trying to loop through an array by step size of 2. what i want is to take 2 values in one iteration and then process it (i.e say i and i+1 index needs to processed in everyloop). for that i wrote following snippet.
for /l %%a in (1,2,!counter!) do (
set username=!array[%%a]!
set /a nextindex=%%a+1
echo username:!username! index: !nextindex! value [!array[%nextindex%]!]
)
when i run this piece of code, the output that i get is :
username:FT_SelfAdmin01 index: 2 value []
username:FT_SelfAdmin01 index: 4 value []
username:FT_SelfAdmin01 index: 6 value []
when i ran the above batch in echo on mode i get following
(
set username=!array[1]!
set /a nextindex=1+1
echo username:!username! index: !nextindex! value [!array[nextindex]!]
)
when i change this line
echo username:!username! index: !nextindex! value [!array[%nextindex%]!]
to this line
echo username:!username! index: !nextindex! value [!array[!nextindex!]!]
i get this (as echo of code)
echo username:!username! index: !nextindex! value [!array[!nextindex!]!]
and output changes to (i am giving only one line here)
username:FT_SelfAdmin01 index: 4 value [nextindex]
i am not able to understand what is happening ?