This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Loop test Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Loop test" Watch "Loop test" New topic

Loop test

Natasha Basu

Joined: Nov 21, 2008
Posts: 10

What is the result of compiling and running the following code?

01. public class LoopTest {
02. public static void goLoop(int a) {
04. start; for (int i = 1; i < 2; i++) {
05. for (int j = 1; j < 2; j++) {
06. if (a > 5) {
07. break start;
08. }
09. System.out.print(i + j);
11. }
12. }
14. }
16. public static void main(String args[]) {
17. LoopTest.goLoop(15);
19. }

The answer is compile time error.
I would like to know why. Can anybody tell me why?
Ankur kothari
Ranch Hand

Joined: Sep 06, 2009
Posts: 531
i hope you know about the ; after start where : should have been
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
Please QuoteYourSources.

Where is this question from?

When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
Natasha Basu

Joined: Nov 21, 2008
Posts: 10
From this website

And thank you for the reply. I did not look for the syntax errors.
nav katoch
Ranch Hand

Joined: May 02, 2008
Posts: 246


wood burning stoves
subject: Loop test
Similar Threads
Strange result in my programm JTEST
why does 'break' traverse one more time
for loop question
Im having problems with writing this program :(
Thread doubt