1//runs as long as the condition is true
2while(condition){
3//do what you want in here
4doStuff()
5}
1// Java infinite while loop
2import java.util.*;
3public class WhileLoopExample
4{
5 public static void main(String[] args)
6 {
7 boolean value = true;
8 while(value)
9 {
10 System.out.println("Infinite loop");
11 }
12 }
13}
1public class WhileLoopDemo
2{
3 public static void main(String args[])
4 {
5 int a = 1;
6 while(a < 10)
7 {
8 System.out.println(a);
9 a++;
10 System.out.print("\n");
11 }
12 }
13}
1int number = 1;
2
3while(number < 10){
4 System.out.println(number);
5 number += 1;
6}
7
8
1int count = 1;while (count < 11) { System.out.println("The count is " + count); count++; // remember, this increases the value of count by 1}