How to use expression for a loop?

Asked By 0 points N/A Posted on -
qa-featured

I have a script like this one below. My aim is to add 1 to variable count in each iteration of the for loop. So, if temp.txt has 10 lines, count will be 10 finally.

set count=1

for /f "eol=v" %%f in (temp.txt) do (
   set /A count = %count% + 1
   echo %count%
)

But I always get count value is 1. I know the statement "set /A count = %count% + 1" is not correct but don't know how to fix it.
I would appreciate insight.

SHARE
Answered By 10 points N/A #97625

How to use expression for a loop?

qa-featured

Hello Sheena,

In which language are you creating your program? Is it C, C++, java or what? Because what I know about setting counts is that there must be a use the -while do- or -do while function somewhere in the code, especially if the language that you are using is java or C++.

The while do function will enable for an increment to be performed as you want once a number functions that you will have declared will have been met.

You can watch more about the -while do loop here:

, and read more about it here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html

__

Regards

Lee Hung

Login/Register to Answer

Related Questions