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.