We help IT Professionals succeed at work.

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 asked
on
106 Views
Last Modified: 2018-02-22
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

NVITEnd-user support
CERTIFIED EXPERT

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 VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

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
CERTIFIED EXPERT
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?
Test your restores, not your backups...
CERTIFIED EXPERT
Expert of the Year 2019
Top Expert 2016
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Shaun VermaakSenior Consultant
CERTIFIED EXPERT
Awarded 2017
Distinguished Expert 2019

Commented:
No feedback from OP