WEB DEVELOPER SITE
PHP7
 

while Loop in java


while loop statement in Java programming language repeatedly executes a target statement as long as a given condition is true.


Syntax

The syntax of a while loop is −

while(Boolean_expression) {
   // Statements
}

Here, statement(s) may be a single statement or a block of statements. The condition may be any expression, and true is any non zero value.

Example

public class Test {

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

        while( x < 18 ) {
            System.out.print("value of x : " + x );
            x++;
            System.out.print("\n");
        }
    }
}
Try it yourself »