Showing posts with label do-while loop. Show all posts
Showing posts with label do-while loop. Show all posts

Java do while loop / Chapter -4/ Flow Control




Java do while loop

Java do while loop:-


If we want to execute loop body at least once then we should go for the do-while loop.

Syntax:-

do
{
         body
}  while (b);         

                         Where; the semicolon is mandatory and b always should be a boolean type.



1. The arguments should be a boolean type. If we are trying to provide any other type then we will get compile time error.

example:
int b=10;
do
{
         body

}  while (b); 

Compile Time Error: Incompatible Type
Found: int
Required: boolean

Java-do-while loop / Chapter -4/Flow Control




b). do -while loop:-
If we want to execute loop body at-least once then we should go for the do-while loop.

Syntax:-

do
{
         body
}  while (b);         

                         where ; the semicolon is mandatory and b always should be a boolean type.



1. The arguments should be a boolean type . If we are trying to provide any other type then we will get compile time error.

example:
int b=10;
do
{
         body

}  while (b); 

Compile Time Error: Incompatible Type
Found:int
Required:boolean

Flipkart End Of Season Sale






© Copyright 2017 Javabychetan.blogspot.com