Java Program To Understand For Loop

      No Comments on Java Program To Understand For Loop

Java for loop is used when you know how many times you want statement or a block of statements to be executed.

SYNTAX:-

for (initialization; condition; increment)
{
    code to be executed;
}

1.Initialization: Initialize the loop counter value. For example: i=1; .

2.Condition: Condition is evaluated for each loop iteration. If it evaluates to TRUE, the loop continues. If it evaluates to FALSE, the loop ends. For example: i<=10; .
3.Increment:Increase the loop counter values. For example: i++ ;.

EXAMPLE:-

class scan
{
	public static void main(String arg[])
	{
		int i;
		for(i=1;i<=10;i++)
		{
			System.out.println(i);
		}
	}
}	

OUTPUT:-

1
2
3
4
5
6
7
8
9
10

Leave a Reply

Your email address will not be published. Required fields are marked *