You are not logged in.

#1 11 Apr 2019 08:11

PiotrMP006
Member
Registered: 02 Apr 2019
Posts: 12

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: 205

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,129

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

#4 06 May 2019 04:27

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

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

I prefer to keep them wherever possible for consistency reasons, but there are definitely times that it's useful to not need them, like when you're dealing with multiple layers of delayed expansion.

Offline

Board footer

Powered by