You have a couple minor errors in your code:
- You have not initialized the counter variable.
- The format of FOR command is slightly different
- A comment is inserted via REM command, not //
This is the right version of your code:
@echo off
setlocal enabledelayedexpansion
set Base_list[0]=Base1
set Base_list[1]=Base2
set Base_list[2]=Base3
set Base_list[3]=Base4
set Base_list[4]=Base5
set Base_list[5]=Base6
set Current_Node=Node1
rem Explicitly set the counter:
set counter=5
if "%Current_Node%" == "Node1" (
for /l %%a in (0 , 1, %counter%) do (
rem do some stuff
echo Element %%a in Base_list array is: !Base_list[%%a]!
)
)
However, this code may be written in a simpler way:
@echo off
setlocal enabledelayedexpansion
rem Create the array via elements placed in a FOR command
rem at same time, generate the counter:
set counter=0
for %%a in (Base1 Base2 Base3 Base4 Base5 Base6) do (
set Base_list[!counter!]=%%a
set /A counter+=1
)
rem Adjust the counter because the array is zero-based:
set /A counter-=1
set Current_Node=Node1
if "%Current_Node%" == "Node1" (
for /l %%a in (0 , 1, %counter%) do (
rem do some stuff
echo Element %%a in Base_list array is: !Base_list[%%a]!
)
)
I suggest you to read this post on array management in Batch files.