sreedevi langoju wrote:Hi,
I am preparing for the OCAJP8 certification.While taking the mock exams i found this question.
Here when this break z; statement will get execute ? If not will it become unreachable statement which gives compilation error ?
when i run this program in eclipse it is running successfully .output: 3567
Thanks in advance,
Sree
Sreedevi,
The continue statement immediately goes to the next iteration of the loop whereas the break statement exits the loop. If you have nested loops, and you use continue or break from within the innermost loop in order to exit an enclosing loop, you can use the break and continue statement with a label so that the compiler knows which loop you are exiting.
I think on reading the code, it would have to be some pretty sophisticated static analyzer to report it as unreachable code. It is unreachable for all means and purposes, but the compiler is not designed to catch this sort of thing.
With best regards,
Anton.
Anton Golovin (anton.golovin@gmail.com) SCJP, SCJD, SCBCD, SCWCD, OCEJWSD, SCEA/OCMJEA [JEE certs from Sun/Oracle]