The functional code is available below:
:: The INDEX control variable is causing the error.
FOR /L %%INDEX IN (%1, %2, %3) DO ECHO %%INDEX
:: Syntax
FOR /L %%parameter IN (start, step, end) DO command
I run this script as follows:
test.bat 0 1 5
I get the following error:
%INDEX was unexpected at this time.
I noticed that this error occurs because of the character count of the control variable (INDEX
) in the FOR
loop. If I update the INDEX
control variable to be a single character (such as X
), the program works as expected.
What are the rules for naming a control variable in a FOR
loop?