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 Labeled while loop problem 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 "Labeled while loop problem" Watch "Labeled while loop problem" New topic

Labeled while loop problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634

by Katherine Sierra (Author), Bert Bates (Author)

Creating a Labeled while Loop
Try creating a labeled while loop. Make the label outer and provide a condition to
check whether a variable age is less than or equal to 21. Within the loop, increment
age by one. Every time the program goes through the loop, check whether age is 16.
If it is, print the message "get your driver's license" and continue to the outer loop. If
not, print "Another year."
-- The outer label should appear just before the while loop begins.
-- Make sure age is declared outside of the while loop.

Is the solution correct ?

OCPJP 6.0 93%
OCPJWCD 5.0 98%
Saruwatari Tadayoshi

Joined: Jun 22, 2010
Posts: 6
I have also just recently completed this exercise and your answer is similar to mine. So I am guessing we are either both correct or both wrong.

Here is my code:

Sahil Kapoor
Ranch Hand

Joined: Sep 12, 2009
Posts: 316
Yess I think , both the solutions are valid.

You can remove "outer" from continue outer; also.

Thanks !!!

SCJP 6.0 96%

(Connecting the Dots ....)
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

IsquishWorms Isquish Worms please check your private messages for some administrative matter...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Saruwatari Tadayoshi

Joined: Jun 22, 2010
Posts: 6
Done sorry about that I should of read the rules.
I agree. Here's the link:
subject: Labeled while loop problem
It's not a secret anymore!