How do I use the while loop statement?

The code below demonstrate how to use the while loop statement. The while statement will check if its expression evaluates to true and execute the while statement block.

The program below will executes while the countDown value is bigger or equals to zero.

package org.kodejava.example.lang;

public class WhileDemo {
    public static void main(String[] args) {
        // Start the count down from 10
        int countDown = 10;

        // Do the count down process while the value of
        // countDown is bigger or equals to zero.
        while (countDown >= 0) {

            try {
                // Adds one second delay.
            } catch (InterruptedException e) {


Programmer, runner, recreational diver, live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. Support me, buy me ☕ or 🍵

Leave a Reply