Thursday, 16 January 2014

Iteration statements : do-while

How to use java do-while:Exit control loop

Using do-while

A do-while is similar to while loop,except that a do-while loop is quaranteed to execute atleast one time. For that you have to use the do while loop in  after that check the condition then we use the do-while loop statement. do-while loop is same as the while loop statement but while loop checks the certain condition is first and if condition is true then statements or processes are executed otherwise all the statements written under the while loop is ignored by the interpreter
but do - while loop executes all the statements first at once and then check the condition if the condition is true then all the statements are also executed in second times otherwise second times ignored all the statement is Exit controlled loop because condition is check at the last moment.Condition expression is written inside while must return  boolean value.

The Syntax for the do-while loop:


Example for simple do-while loop

// Demonstrate the do-while loop.
  public class DoWhileSample
  public static void main(String args[])
  int n=10;
  System.out.println("value of n :"+n);
  This would produce the following results
  value of n=11
  value of n=12
  value of n=13
  value of n=14
  value of n=15
  value of n=16
  value of n=17
  value of n=18
  value of n=19

Control Flow of switch Statement

No comments :

Post a Comment