aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes continue doubt... 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 "continue doubt..." Watch "continue doubt..." New topic
Author

continue doubt...

Arun Kumaar
Greenhorn

Joined: Oct 22, 2004
Posts: 20
though my question seems to be silly, but something in it is nagging me...

1. int I = 0;
2. label:
3. if (I < 2) {
4. System.out.print("I is " + I);
5. I++;
6. continue label;
7. }

The above code will give a compile time error, since the continue is not within the loop, but isn't it residing inside the if loop construct.

Regards
Arun


If I could melt your heart<br />We'd never be apart<br /> <br />Frozen --- Madonna
Damien Howard
Ranch Hand

Joined: Apr 01, 2003
Posts: 456
if is not a loop it is a conditional statement. continue and break are specifically for loops. This means for, while and do while loops

continue means stop execution here and begin at the next iteration fo the loop. since if is only run once and is not looped it does not make sense to use continue with an if statement
[ May 23, 2005: Message edited by: Damien Howard ]
Arun Kumaar
Greenhorn

Joined: Oct 22, 2004
Posts: 20
Doesn't it becomes a looping construct when combined with continue...

Regards
Arun
Tom Johnson
Ranch Hand

Joined: May 11, 2005
Posts: 142
No its still a conditional,


<a href="http://faq.javaranch.com/java/UseCodeTags" target="_blank" rel="nofollow">Use Code Tags!!</a>
Damien Howard
Ranch Hand

Joined: Apr 01, 2003
Posts: 456
Originally posted by Arun Kumaar:
Doesn't it becomes a looping construct when combined with continue...

Regards
Arun


continue means to begin the next iteration, but since if is not a loop there is no next iteration.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

Doesn't it becomes a looping construct when combined with continue...


If Java allowed it, it would effectively become a loop. but it's not allowed. a continue statement can only be inside the body of one of the three defined loops.

I'm sure if you read the Java Language Specification, it'd spell it out a little more formally. But for now, you'll just have to take our word for it!!!

:-)


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: continue doubt...