0

I want to create a for loop that uses user input variables in it's parameter. Here is what I have:

@ECHO off
DEL "./positions.txt"
SET /P start_position= Please enter the start position:
SET /P end_position= Please enter the end position:
SET /P step_size= Please enter the step size:
FOR /L %%A IN (%start_position%,%end_position%,%step_size%) DO (
    ECHO %%A >> positions.txt
)
ECHO( & echo.Done! "positions.txt" was generated. & echo.
pause

However this doesn't seem to work. Here is what I get on the output:

>> Done! "positions.txt" was generated.

It runs, but skips over the for loop. What is wrong?

1 Answer 1

3

for /L loops use the order start, step, end.

FOR /L %%A IN (%start_position%,%step_size%,%end_position%) DO (
    ECHO %%A >> positions.txt
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much! I still have C programming stuck in my head.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.