File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

for loop

 
jenda
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello!

Can some one tell me how to use a for loop
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. The Java Tutorial at Sun can.
 
Barry Higgins
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically a for loop lets you step through a certain action or set of actions a set number of times.
It generally has the signature:

for (int i=0; i<10; i++) {

}

which means proceed though this action 10 times.

int i=0 set the initial value to 0
i<10 checks that the value is still under 10
i++ adds one to i and the whole thing goes round again until step 2 is no longer true then it exits.

for (int i=0; i<10; i++) {
System.out.println("i now equals : " + i);
}

Try putting this code into a main and running it/changing the values around.

P.S This is only a very basic description .. there are many different permutations of this basic form which will add different functionality.
You're best bet is to get a good Java book and check through the basics
Have a look at Thinking in Java (it's a free download)


Bruce eckel's site
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
jenda,

Welcome to JavaRanch!

We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.

We request that display names follow the pattern FIRST_NAME + SPACE + LAST_NAME.

Thanks Pardner! Hope to see you 'round the Ranch!
 
Dirk Schreckmann
Sheriff
Posts: 7023
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic