i have a batch file. i want to print all the values but it also displays the last value of for loop.

meet sidhu
meet sidhu used Ask the Experts™
on
i have enter 3 tasks but it only displays last task. how i can display all the tasks.
@echo off
echo Enter Your Tasks::
setlocal enabledelayedexpansion
for /L %%a in (1 1 3) do (
set /p xx= %%a
)
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NVITEnd-user support

Commented:
Not sure what you're trying to do but, what you have doesn't display any value of XX. Not even the last, as you say.
This displays each value:
@echo off
setlocal enabledelayedexpansion
echo Enter Your Tasks::
for /L %%a in (1 1 3) do (
  set /p xx= %%a
  echo !xx!
)

Open in new window

Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
@echo off
setlocal enabledelayedexpansion
echo Enter Your Tasks::

set maxTasks=3
for /L %%a in (1 1 %maxTasks%) do (
  IF %%a NEQ %maxTasks% (set /p xx= %%a)
)

Open in new window

Qlemo"Batchelor", Developer and EE Topic Advisor
Top Expert 2015

Commented:
Shaun, that will display 2 prompts only. No clue how that is related to what the OP asked for?

Meet, I'm confused as the other Experts. The batch file asks for 3 "tasks", displaying a prompt for each with visual feedback about the input. So what is missing?
IT / Software Engineering Consultant
Top Expert 2016
Commented:
If you are looking for a way of capturing 3 entries for three different tasks, then you could assign each to a different variable and use them.  Here's one approach to that, creating variables named with the task number in their name.  There are other approaches that could be used, but thought this might give you some ideas.

@echo off
setlocal EnableDelayedExpansion

echo Enter Your Tasks:

for /L %%a in (1 1 3) do (
  set /p "Task[%%a]=Task %%a: "
)

echo %Task[1]%
echo %Task[2]%
echo %Task[3]%

Open in new window

~bp
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
No feedback from OP

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial