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}
1A while loop iterates a block of statements until condition is true. In a
2while loop condition is executed first.
3Syntax:
4
5while(condition)
6{
7 // code goes here
8}
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++;