Murtuza,
Thank you for using my exam.
The
Java Language Specification defines a do statement as follows.
do Statement while ( Expression ) ;
A statement ends with a semicolon, so the compiler knows that the "while" keyword must be preceded by a semicolon. When a while loop is nested inside of a do loop, the nested while is not preceded by a semicolon.
Of course, I don't really know how the compiler parses the source code. The above is just a description of how I think it could be done.