Reputation:
I'm trying to loop 100 times in command prompt and each time change the console color (with values lying between 0 and 7 used to set the possible colors).
However when I try to use color %variablename%
I always get the same value.
Here is the code:
for /l %i in (0,1,99) do set /a var= %i % 8 & color %var%
The output form the line set /a var= %i % 7
is right, that is 0,1,2,3,4,5,6,7,0,1,2,3,4,.......
However, when I call %var%
on each loop, instead of displaying different results each time it always displays the same one, thus the color changes only once and remains the same for the whole loop.
What am I doing wrong?
Upvotes: 0
Views: 710
Reputation: 38654
In the command prompt:
For /F %B In ('"For /L %A In (0 1 99) Do @Set/A %A%8&Echo="') Do @Color %B&Timeout 1 /NoBreak>Nul
I put a 1
second timeout
in there so that you can see the effect, press CTRL+C to exit early.
Upvotes: 2
Reputation:
batch file, added timeout /t 1
to display effect, assuming this is what you meant.
@echo off
cls
setlocal enabledelayedexpansion
for /l %%i in (0,1,99) do (
set /a var=%%i %% 8
echo !var!
timeout /t 1 >nul
call color !var!
)
Upvotes: 0