Home Java Jdk7 Looping Statements in java 7
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

Looping Statements in java 7

Advertisement
In this section, we will discuss about Looping Statements in java 7. This is one type of control flow statement.

Looping Statements in java 7

In this section, we will discuss about Looping Statements in java 7. This is one type of control flow statement.

Looping Statements :

This kind of statements are used where you need to execute block of statements repeatedly. Following are three types of Looping statements -

  • for loop
  • Do-while loop
  • while loop

1. For Loop :

For loop provides a way to repeat block of code under particular condition. It is single line statement. It contains three terms-initialization, condition and increment/decrement.

Syntax:

for(initialization; Boolean termination; increment/decrement)
{.......
...... //Statements
}

initialization : In initialization, we assign some initial value to the loop variable and it is executed only once during the execution of for loop.

termination/condition : This is the point where your loop stop. We write some condition here.

increment/decrement : If condition is true then your variable either increment or decrement as you specify.

2. Do-while Loop :

It is a control structure which is similar to while loop except that a do-while loop is guaranteed to execute at least one time.

Syntax:

do{
//statements
}
while(boolean_expression);

Here expression is declared at the end of the loop, so that the statements in the loop will get execute once before the expression is tested. If the condition is true, the flow of control jumps back to do, and the statements in the loop execute again. It repeats until the condition is false.

3. While 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.

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 22, 2012

Related Tutorials

Ask Questions?    Discuss: Looping Statements in java 7  

Post your Comment


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