There is Different types of Loops in Java Programming

  • For Loop
  • Do While
  • While

For Loop

Syntax : 
for (Initialise ; Condition; Increment / Decrements) {
//Operation Statement
}

Example :
for (i=0; i<10; i++) {
System.out.println(i);
}

Its Display  0123456789

Program :

public class Basic_for_loop {
	public static void main(String[] args) {
		System.out.println("Table of Two:");
		for (int number = 1; number <= 10; number++) {
			System.out.println("2*" + number + " = " + number * 2);
		}
	}
}

Output :

Basic_for_loop

Do While Loop

Syntax : 
Initialise;
Do{
//Operation Statement
//Increment / Decrements
}
while(Condition)

Example :
i=0;
do{
System.out.println(i);
i++;
}while( i<10);

Its Display  0123456789

Program:

public class Basic_do_while_loop {
	public static void main(String args[]) {
		System.out.println("Table of Seven: ");
		int number = 1;
		do {
			System.out.println("7*" + number + " = " + number * 7);
			number++;
		} while (number <= 10);
	}
}

Output :

Basic_do_while_loop

While Loop

Syntax : 
Initialise;
while( Condition){
//Operation Statement
//Increment / Decrements
}

Example :
i=0;
while( i<10){
System.out.println(i);
i++;
}
Its Display  0123456789

Program:

public class Basic_while_loop {
	public static void main(String[] args) {
		System.out.println("Table of two: ");
		int number = 1;
		while (number <= 10) {
			System.out.println("2*" + number + " = " + number * 2);
			number++;
		}
	}
}

Output :

Basic_while_loop

(Visited 197 times, 1 visits today)
Share with Friends :
Written by: