Java while Loop

Last Updated: March 17, 2022

Java while loop syntax

while (condition) {
  // code block to be executed
}

Java while loop example

Iterate over the array using while loop

int[] numbers = { 125, 132, 95, 116, 110 };
int i =0;
while(i<numbers.length){
     System.out.println("Number is "+numbers[i]);
     i=i+1;
 }

Java do while loop

Test