File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes For Stament with continue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "For Stament with continue" Watch "For Stament with continue" New topic

For Stament with continue

sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
Hi This is code snippet form K&B page no 343.Plese explain me why the outer is not printing hear???

for (int i=0; i<5; i++) {
for (int j=0; j<5; j++) {
continue outer;
} // end of inner loop
System.out.println("outer"); // Never prints

output is

Thnaks in advance
Ashish Hareet
Ranch Hand

Joined: Jul 14, 2001
Posts: 375
From the jls - "A continue statement with label Identifier attempts to transfer control to the enclosing labeled statement (�14.7) that has the same Identifier as its label; that statement, which is called the continue target, then immediately ends the current iteration and begins a new one"

Based on the above statement, in your code example, every time "continue outer" is called, the control is transferred to the for statement with the label "outer" to start the next iteration. The code never reaches the print statement.

Try the same example with "continue;" instead of "continue outer;"

Ashish Hareet
I agree. Here's the link:
subject: For Stament with continue
It's not a secret anymore!