Using a 'for' loop in batch file programming to display the first N natural numbers

Tag: windows , loops , windows-xp , batch-file , for-loop Author: wood67 Date: 2010-09-01

I would like to mainly know the working of a for loop. For this I think a small sample program will be helpful to me. So what is a simple program to display the first N natural numbers?

Best Answer

If you are talking about Windows batch programming here you have a natural numbers generator:

for /L %i IN (0,1,9) do @echo %i

Other helpful links to deal with files and so on:

If you are talking about GNU Linux/Unix bash scripting you can go to:

Hope that helps,


Thanks for the earlier reply. /L stands for what? Please reply.
Look at "FOR /?" for help. /L does a sequence from "start" to "end" in increments of "step". In this case, from 0 to 9 in steps of 1. Official syntax: "FOR /L %variable IN (start,step,end) DO command [command-parameters]"
@sarika: /l or /L is for loop. Easy, ah?
thanks... comments closed