DEV Community

Vignesh . M
Vignesh . M

Posted on

WHILE LOOP

  • The while loop in Java is a control flow statement that repeatedly executes a block of code as long as a given condition is true. It is an entry-controlled loop, meaning the condition is checked before the loop body is executed. SYNTAX
while (condition) {
    // Code to be executed repeatedly
     Incerment //decerment operater
}

Enter fullscreen mode Exit fullscreen mode

condition:
* A boolean expression that determines whether the loop should continue.
Code block:
* The set of statements that will be executed repeatedly as long as the condition is true.

Image description

EXAMPLE PROGRAM:

public class WhileExample {
    public static void main(String[] args) {
        int count = 0;
        while (count < 5) {
            System.out.println("Count is: " + count);
            count++;
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

OUTPUT:
0
1
2
3
4

REFERRED LINKS :

  1. https://www.geeksforgeeks.org/java/java-while-loop-with-examples/
  2. https://www.datacamp.com/doc/java/java-while-loop

Top comments (0)