" while " statement is also used as the looping statement in any programming languages. It only works with the condition and we can use updation statement inside the block otherwise it will go for infinite loop if the condition is true.

Syntax of while statement is :
while ( condition ) { } 

Some of the invalid code with the use of while statement


while ( true ) { }
System.out.println (" Error ") ;

Here compiler give compilation error saying " unreachable statement "  because it will go for infinite loop and never execute the statements after while block.

while ( false ){ System.out.println (" Error ") ; }

Here compiler give  " unreachable statement " compilation error and condition is false so block statement will never execute.

while (  ) { } 

The above syntax is incorrect because there must be some condition to be checked while executing while block.

" do-while " looping statement 

" do - while " is same as " while " but the only difference is that in do-while the statement will execute at least once and rest execution will depend upon the condition.

Syntax of do-while statement :
do {
// statement 
< updation > }
while ( condition ) ;

Here it will execute statement of do block even if while condition is false. 

Related Posts:

  • " break " control statement break statement is used to control the transfer out the block without executing the statements written after break statement . It is used either with switch or looping statement. Syntax of break statement : break ;  or… Read More
  • " while " looping statement " while " statement is also used as the looping statement in any programming languages. It only works with the condition and we can use updation statement inside the block otherwise it will go for infinite loop if the condit… Read More
  • If Statement in Java As we know that " if " is a conditional control statement and maximum it will execute once depending upon the condition check. If the condition is true then it will execute once and if false then will not execute at even fo… Read More
  • " for " Looping statement Any looping statement is comprises of there stages i.e 1> Initialization                   2> Conditional                   &n… Read More
  • Switch control statement In programming languages switch is a type of conditional control statement. It has one switch statement and many cases with one default statement. Depending upon the switch value it matches with the cases value and execute … Read More

1 comment:

Blog Archive

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201978

Online Members

Live Traffic