File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes FOR    LOOP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "FOR    LOOP" Watch "FOR    LOOP" New topic


amir zaheer

Joined: Aug 14, 2001
Posts: 2
i m new to java and trying to lern the basics. i have understood
what FOR LOOP is but i cant understand the logic to put while mking a programme
i have tried to understand from different books how the FOR LOOP
works but cant mke programme as i desire
can any one send me detailed and simple notes to understand FOR LOOP operation
Greg Harris
Ranch Hand

Joined: Apr 12, 2001
Posts: 1012

compile and run this... it counts from 1 to 10 because of the for loop.
"i is set to "1"
for( int i = 1 ;
and is incremented by 1 each "loop"
i++ );
until it is "<= 10"
i <= 10 ;
then the loop terminates.

[This message has been edited by Greg Harris (edited August 14, 2001).]

Johannes de Jong

Joined: Jan 27, 2001
Posts: 5089
Hi amir I'm moving this topic to "Java in General (Beginner)" forum.
Good luck learning java
good catch though Greg
Muhammad Siddiq

Joined: Aug 15, 2001
Posts: 3
Loops are basically used for iterations(repeatation). It's not only in java but used in other computer languages also for the same purpose. For eg. if u to print your name ten times. There
are two approaches to this problem.
1) is to write the statement System.out.println("Your Name"); ten times. This is not appreciable because it makes your code longer and inefficient.
2)The other is to use a for loop,while loop or a do-while loop.

The syntax for the For loop is
body of loop
lets implement the example stated above using the for loop.
class yname
public static void main (String [] args)
int i=1;
System.out.println("Your Name");
This code will print "Your Name" ten times.
I m also a java beginner. If u have further questions regarding for loop, plz dont hesitate to ask.

I agree. Here's the link:
subject: FOR LOOP
It's not a secret anymore!