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
1do while loop java executes the statements and then evaluates the
2expression/condition of loop’s body until given condition is true.
3Here’s do while loop syntax in java.
4
5// do while loop java
6do{
7 statement(s);
8}while(expression/condition);
1
2package com.journaldev.javadowhileloop;
3
4public class JavaDoWhileLoop {
5
6 public static void main(String[] args) {
7
8 int i = 5;
9 do {
10 System.out.println(i);
11 i++;