November 3 2014

While Statement In Java

While loop repeats  group of statements as long as condition is true. Once the condition is false the loop is while statement in javaterminated.

While Statement In Java – Syntax : 




Example Program

package loops;

public class WhileExample {

public static void main(String[] args) {

int x=1; // Initial Value

System.out.println(" Value of x : " +x);
x++; // Incrementing value of x




Output :


Value of x : 1
Value of x : 2
Value of x : 3
Value of x : 4
Value of x : 5


Initially the value of x is 1. First time the condition in the while is true so it will execute the while statements and  value of x is incremented by 1.Condition will be true until the values of x becomes 6 .Once the condition is false it will come out of the loop.

Copyright © 2014. All rights reserved.

Posted November 3, 2014 by answersz in category Bluej Java Programs for ICSE Class 10 and 9 Practice, Core Java

Leave a Comment

Your email address will not be published. Required fields are marked *