aspose file tools*
The moose likes Beginning Java and the fly likes for loops Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "for loops" Watch "for loops" New topic
Author

for loops

Bob Holland
Greenhorn

Joined: Dec 15, 2004
Posts: 7
hi there, how do i use a for loop, and what is the correct syntax please?? Bob
Keith Biddlecomb
Greenhorn

Joined: Jan 25, 2005
Posts: 5
for (int i = 0; i < 5; i++) {
//your code goes here
}

This loop will repeat itself 5 times. I'm not sure how familiar you are with the i++ syntax, but it is the same as i = i + 1, so if you feel more comfortable writing that in the loop instead, it would also work. Just a word of caution, make sure, in general, you DO NOT redefine i (or whatever variable you choose to use as the counter) inside the loop. That is a very easy way to cause an endless loop.


Keith Biddlecomb<br />Computer Science<br />University of Virginia
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Since your signature indicates you are in the Computer Science department at the University of Virginia, I assume you are learning Java as part of your cirriculum. If this is the case, you should be able to find explanations about Java syntax in your text book, so READ IT! If you don't find your textbook very clear on a particular topic, perhaps you can post a quote here so we can clarify what the author probably means.

If you are just learning Java on your own, rather than in a class currently, or if you want additional resources to help you learn the language, I would suggest that you check out Sun's Java Tutorial. It has some great lessons to get you up to speed on the basic syntax of the language.

Keep Coding!

Layne


Java API Documentation
The Java Tutorial
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Layne Lund:
Since your signature indicates you are in the Computer Science department at the University of Virginia ... you should be able to find explanations about Java syntax in your text book, so READ IT! ...

where "..." = (snip).

That's Keith's signature, who posted a reply to the original question from Bob.

(Just want to be fair to Keith. )


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by marc weber:

where "..." = (snip).

That's Keith's signature, who posted a reply to the original question from Bob.

(Just want to be fair to Keith. )

Doh! :roll: Apparently I need to read more carefully myself. My apologies Keith.

Layne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: for loops
 
Similar Threads
while loop
Codes For Practice
for and while loops
WA #2 ..... word association
WA #1.....word association