| Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free! |
variables in batch FOR loops
|
Original Message
|
Name: oldog
Date: April 6, 2008 at 20:51:31 Pacific
Subject: variables in batch FOR loopsOS: win xp pro sp2CPU/Ram: c2duo/3gbModel/Manufacturer: dell |
Comment: Hi all! Probably a silly question, but I'm rather new to batch programming and the following just doesn't make sense to me at all! @ECHO OFF SETLOCAL SET CNTR=0 FOR %%i IN (one,two,three) DO ( SET /a CNTR=CNTR+1 ECHO %CNTR% ) ECHO %CNTR% GOTO :EOF
I'm expecting the output to show 1 2 3 3
but I get 0 0 0 3 There's obviously something I don't get about defining and using variables... Any help appreciated!
Report Offensive Message For Removal
|
|
Response Number 2
|
Name: Mechanix2Go
Date: April 7, 2008 at 06:46:43 Pacific
|
Reply: (edit)For simplicity, you can skip onotialing the var. And increment like this: ::== @echo off setLocal EnableDelayedExpansion for %%a in (one two three) do ( set /a cntr+=1 echo !cntr! ) echo !cntr! ===================================== If at first you don't succeed, you're about average.M2
Report Offensive Follow Up For Removal
|

Post Locked
This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
Go to Programming Forum Home