Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » FundamentalRSS Feeds

While Loop

Posted By: Jiro Yoshida     Category: Java     Views: 3563

This article explains about while loop in java with examples.

While statement provides form of loop.  While loop can contain statement or block of statements.

Syntax of While Loop

while(expression) statement;

expression is any expression. Loop will get executed till the expression returns true. Value of the expression is checked at the top of the loop.


Examples of While Loop

Example 1 : Program that prints 1 to 10 

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

System.out.print("Numbers : ");

while(i >= 10)
{
System.out.print(i + " ");
i++;
}
  }
}


Output

Numbers : 1 2 3 4 5 6 7 8 9 10


  
Share: 


Didn't find what you were looking for? Find more on While Loop Or get search suggestion and latest updates.

Jiro Yoshida
Jiro Yoshida author of While Loop is from Kyoto, Japan.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!