jQuery in Action, 2nd edition*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Flow control Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Flow control" Watch "Flow control" New topic
Author

Flow control

pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
this one is also by marcus green
public class Cjgreen{
public static void main(String argv[]){
Cjgreen c = new Cjgreen();
c.jgreen();
}
public void jgreen(){
int iNum =1 ;
while(iNum >0){

toffer:
for(int i = 0; i < 3; i ++){
continue toffer;
System.out.println(i);
}
}

iNum --;
}
}
The Correct Answer is
1) Compile time error
The java compiler will recognise that the System.out.println command will never be reached and will cause a compile time error
i thought the answer is compilation but no output at runtime
can anyone explain this plz


Thanks,<br />Pallavi
Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
Hi,
I'm in a bnit of a hurry so I'll just give u some pointers, if is something unclear please post again
So:
System.out.print (....) is an experssion statement
the below is from JLS 14.20
"An expression statement can complete normally iff it is reachable.
A break, continue, return, or throw statement cannot complete normally.
The first statement in a nonempty block that is not a switch block is reachable iff the block is reachable. "
and this is tmhe most important
"Every other statement S in a nonempty block that is not a switch block is reachable iff the statement preceding S can complete normally."
since continu vannot compelete normally System.out(...) is unreacheable
Hpe I make sense
see you soon


"Did anyone understand what I have just explained? ... because I did not!"
Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
oops.. disregard the line below from the first quote:
"The first statement in a nonempty block that is not a switch block is reachable iff the block is reachable"
Also note that if you put the continue in an If clause you avoid the compilation error:
"An if-then statement can complete normally iff it is reachable. The then-statement is reachable iff the if-then statement is reachable."
jls 14.20
pallavi utukuri
Ranch Hand

Joined: Feb 10, 2004
Posts: 182
"An expression statement can complete normally iff it is reachable.
A break, continue, return, or throw statement cannot complete normally.
The first statement in a nonempty block that is not a switch block is reachable iff the block is reachable"
i am not able to understand this its sounding too hi-fi plz be more clear na thanks
Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
to get the concepts read jls 14.20, If I get into details I'll just repeat the text there
kiran goud
Greenhorn

Joined: Apr 21, 2004
Posts: 23
could any one tell me whatis jls ??
Dan Andrei
Ranch Hand

Joined: Jan 21, 2004
Posts: 92
java language specification - jls
Ruchi Sharma
Greenhorn

Joined: Mar 24, 2004
Posts: 6
Kiran,
You can download JLS from this link:
http://java.sun.com/docs/books/jls/second_edition/html/jTOC.doc.html
Ruchi.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Flow control
 
Similar Threads
continue
Indefinite loop
Run- time Error OR Compile time Error
What is this unreachable error
Powerball program for school, Need to to run program 8 times.