Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Jdk7 While Loop Statement in java 7

Related Tutorials


 
 

Share on Google+Share on Google+

While Loop Statement in java 7

Advertisement
This tutorial, helps you to understand the concept of while loop in java 7.

While Loop Statement in java 7

This tutorial, helps you to understand the concept of while loop  in java 7.

While Loop Statements :

While loop is most used loop in programming. We put the condition with in the while loop and if condition satisfied then the while block executes otherwise break the loop. You can use any counter to iterate the loop. This type of control structure repeat the task certain number of times. It is more easier to understand in comparison to for loops.

Syntax :

while(boolean_expression){
//statement
}

When executing, if the expression result is true then statement inside the loop will get executed and it will continue as long as the expression result is true.

Example :

Here is Simple example of while loop.

package looping;

class WhileLoop {
	public static void main(String[] args) {
		int i = 1;
		System.out.println("While loop example");
		// Using while loop
		while (i <= 10) {
			System.out.println("Hello " + i);
			i++; // incrementing i with 1
		}
	}

}

Output :

While loop example...
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
Hello 10
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 24, 2012

Related Tutorials

Discuss: While Loop Statement in java 7  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com