#1 11 Apr 2019 08:11

PiotrMP006
Member
Registered: 02 Apr 2019
Posts: 5

Why is it not working? for /l %%a in (1,1,%width%-1) do echo %%a

Hi

Why is it not working?

%width%-1

ex

set width=80
for /l %%a in (1,1,%width%-1) do echo %%a

Offline

#2 11 Apr 2019 08:56

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 170

Re: Why is it not working? for /l %%a in (1,1,%width%-1) do echo %%a

You can only do math with the set /a command, so you'd need to say

set width=80
set /a max_value=%width%-1
for /L %%A in (1,1,%max_width%) do echo %%A

Offline

#3 12 Apr 2019 07:59

bluesxman
Member
From: UK
Registered: 29 Dec 2006
Posts: 1,068

Re: Why is it not working? for /l %%a in (1,1,%width%-1) do echo %%a

Following on from Shadow Thief's post, set /a has a nice feature allowing you to omit the % from variables, to make your calculations easier to read.

set width=80
set /a max_value=width-1
for /L %%A in (1,1,%max_width%) do echo %%A

cmd | *sh | Ruby | Chef

Offline

Board footer

Powered by FluxBB