How do I use the do-while loop statement?

Category: fundamental, viewed: 740 time(s).

There is also a do-loop in the Java programming language. Instead of evaluating the expression at the beginning like the while loop does the do-while loop evaluates its expression at the end of the loop. Due to this the loop executes at least once during the program execution.

package org.kodejava.example.lang;

public class DoWhileDemo {
    public static void main(String[] args) {
        int i = 0;

        //
        // The do-while statement executes at least once because
        // the expression is checked at the end of the loop
        // process.
        //
        do {
            //
            // This block will be executed while i is smaller or
            // equals to 10.
            //
            System.out.println(i);
            i++;
        } while (i <= 10);
    }
}

The program prints the following result:

0
1
2
3
4
5
6
7
8
9
10
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Uncensored Newsgroups
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Java Training

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats