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}
1do {
2 //something you want to execute at least once
3} while (someBooleanCondition);
4
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}
1while(i < 5) //while i < 5 stay in the loop
2{
3 System.out.print(i);
4 i++;
5}
6/*
7 do someting
8 change variable
9 call methods
10 etc...
11*/