Tuesday, 25 April 2017

Java while loops ~ foundjava

Java while loops statement allows to repeatedly run the same block of code, until a condition is met.
Syntax:
While (condition)
{
   statement(s);
   Incrementation;
}
java-while
Example:
public class Sample {

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

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

java-while-loop

No comments:

Post a Comment