Page 1 of 1

Semicolon in do-while

Posted: Wed Mar 06, 2013 7:55 pm
by Sweetpin2
Hi,

Is it mandatory to have the semicolon after while in do-while statement. I read it some where & it says it's not mandatory but when i don't give it i am getting compilation error.

So is there any code example to clarify my doubt?

Re: Semicolon in do-while

Posted: Wed Mar 06, 2013 8:13 pm
by Guest
Sweetpin2 wrote:Hi,

Is it mandatory to have the semicolon after while in do-while statement. I read it some where & it says it's not mandatory but when i don't give it i am getting compilation error.

So is there any code example to clarify my doubt?
as per OCA Java SE 7 Programmer I Certification Guide

NOTE: Don’t forget to use a semicolon (;) to end the do-while loop, after specifying its condition. Even some of the experienced programmers overlook it!

Re: Semicolon in do-while

Posted: Thu Mar 07, 2013 7:21 am
by admin
Yes, it is mandatory as per http://docs.oracle.com/javase/specs/jls ... #jls-14.13
DoStatement:
do Statement while ( Expression ) ;