Tuesday 25 April 2017

Java do while loops ~ foundjava

Java do while loops is very similar to the java while loops, but it always executes the code block at least once and further more as long as the condition remains true.
Syntax:
do
{
   statement(s);

}while( condition );
java-do-while
Example:
public class Sample {

    public static void main(String args[]) {
        /* local variable Initialization */
        int n = 1, times = 0;

        /* do-while loops execution */
        do {
            System.out.println("Java do while loops:" + n);
            n++;
        } while (n <= times);
    }
}
Program Output:

java-do-while-loop

No comments:

Post a Comment