Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 828
Sarika.S Avatar asked Sep 17 '10 08:09

Sarika.S


People also ask

What does %% do in batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.

What is %% g'in batch file?

%%parameter : A replaceable parameter: in a batch file use %%G (on the command line %G) FOR /F processing of a command consists of reading the output from the command one line at a time and then breaking the line up into individual items of data or 'tokens'.


1 Answers

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:

  • http://www.computerhope.com/forhlp.htm
  • http://ss64.com/nt/for.html

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

  • http://www.cyberciti.biz/faq/bash-for-loop/

Hope that helps,

like image 118
Ramon Araujo Avatar answered Oct 07 '22 02:10

Ramon Araujo