While Loop In Java Example

Chapter: Control Statements Last Updated: 08-06-2017 13:54:21 UTC

Program:

            /* ............... START ............... */
                public class JavaWhileLoop {
	public static void main(String args[]) {
		int i = 10;
		while (i > 1) {
			System.out.println(i);
			i--;
		}
	}
}
                /* ............... END ............... */
        

Output

10
9
8
7
6
5
4
3
2

Notes:

  • The while statement continually executes a block of statements while a particular condition is true.
  • Difference between do-while and while is that do-while evaluates its expression at the bottom of the loop instead of the top in while loop.
  • If the number of iteration is not fixed, it is recommended to use while loop.

Tags

While Loop, Java

Similar Programs Chapter Last Updated
Java For Loop And ForEach Loop Example Control Statements 03-09-2016
Java Enum And Switch Statement Control Statements 03-09-2016
Control Statements In Java Example Control Statements 19-06-2016
If Statement In Java Example Control Statements 17-06-2016
Java Switch Example Control Statements 14-06-2016
Return Statement In Java example Control Statements 15-07-2016
Print Stars In Java Example Control Statements 15-07-2016
Nested Loop In Java Example Control Statements 15-07-2016
Infinite While Loop In Java Control Statements 10-06-2016
Infinite Loop In Java Example Control Statements 15-07-2016
If Else Statement In Java Example Control Statements 10-06-2016
For Loop In Java Example Control Statements 07-06-2017
For Each In Java Example Control Statements 07-06-2017
Do While Loop In Java Example Control Statements 10-06-2016
Continue Statement In Java Example Control Statements 30-03-2017
Java Break Statement Example Control Statements 06-07-2016

1