java tutorial - Java Loop While - java programming - learn java - java basics - java for beginners

Java loop while

Learn Java - Java tutorial - Java loop while - Java examples - Javaprograms

The while loop - repeatedly executes the target of the operator as long as the condition is true.


  • The syntax of the while loop in Java:
     while (Boolean expression)
   // Operators
click below button to copy the code. By - java tutorial - team
  • There can be one operator or group of operators. The condition can be any expression, true (true), or any non-zero value.
  • When executed, if the result of the logical expression is true, then the actions inside the loop will be executed. This will continue as long as the result of the expression is true.
  • When the condition becomes false, the program passes control to the line immediately after the loop.

Process diagram


Learn java - java tutorial - java while loop - java examples - java programs

  • The key point of the while loop in Java is that the loop can never be executed.
  • When the condition is checked and the result is false, the loop body will be skipped and the first line after the while loop will be executed.

Sample Code

public class Test {

   public static void main(String args[]) {
      int y = 10;

      while( y < 15 ) {
         System.out.print("Value y: " + y );
click below button to copy the code. By - java tutorial - team


Value y: 10
Value y: 11
Value y: 12
Value y: 13
Value y: 14

Related Searches to Java Loop While