Our social:

Wednesday, October 5, 2016

Loop Types in Java-Tutorial

In Java, if programmer uses loops to to perform "specific operation" multiple times. The "specific operation" are called "controlled statements" or "body of a loop" which should be kept inside the loop body.



The body of a loop gets executed repeatedly until the condition becomes false or the programmer breaks the loop.


In above diagram, if the body of a loop contains a break; statement then the loop gets break.

Loop Type in Java

While LoopWhile a given expression is true it repeats the statement in the loop body. Before executing
the loop body it tests the condition for true or false.
Do-while LoopIt is like a while loop but it tests the condition after executing the loop body.
For LoopIn above two loops we need to write the increment or decrement operation to break the loop after sometime. But in for loop we have an option of incrementing or decrementing outside the loop body.
For Each LoopThis loop applies a function to the range of elements in a collection.
Nested LoopWhen using one or more loops inside a loop is known as nested loop.

Loop Control Statements in Java

By using loop control statements we can change the flow of execution of statements inside the loop body. Java supports two control statements as mentioned below.

 Control Statement
 Description
break statementBreak terminates immediately the loop statement from executing further and execution reaches just outside the loop body containing the break statement.
continue statementContinue statement is equivalent to going to the very end of the loop immediately by skipping further statements.


     
        

 While Loop in Java

0 comments:

Post a Comment

Hello Every One thanks For Visit My site You Can Suggest any Idea About site And Related Education Information Provide me Its Best Content For you am Include in this Site And feel free contact And email now I hope This site very help full you