While loop:
§ This is called entry control loop
§ While loop gets executed as long as the condition is true
§ Condition is evaluated first and then statements.
§ Minimum number of execution in this case is “zero”
§ syntax:
while ( condition )
{
Statements
}
Example:
int i=0;
while( i<10 )
{
System.out.println(“hello”);
i=i+1;
} /* prints hello 10 times */
Do while loop:
§ This is called exit control loop.
§ Do-While loop gets executed as long as the condition is true
§ Statements get executed first and then Condition.
§ Minimum number of execution in this case is “one”
§ Syntax:
do
{
Statements
}while(condition);
Example:
int i=0;
do
{
System.out.println(“hello”);
i=i+1;
} while(i<10); /* prints hello 10 times */
0 comments:
Post a Comment