File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "FOR    LOOP" Watch "FOR    LOOP" New topic
Author

FOR LOOP

amir zaheer
Greenhorn

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
thanks
amir
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).]


what?
Johannes de Jong
tumbleweed
Bartender

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
Greenhorn

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
for(initialization_expression;conditonal_expression;increment_expression)
{
body of loop
}
lets implement the example stated above using the for loop.
class yname
{
public static void main (String [] args)
{
int i=1;
for(i=1;i<11;i++)
{
System.out.println("Your Name");
}
}
}
Output
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.
Thanks.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FOR LOOP
 
Similar Threads
Question on gc
continue trouble
FOR LOOP
Isolating one line
need help!