Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flow control

 
pallavi utukuri
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Andrei
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dan Andrei
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
to get the concepts read jls 14.20, If I get into details I'll just repeat the text there
 
kiran goud
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could any one tell me whatis jls ??
 
Dan Andrei
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java language specification - jls
 
Ruchi Sharma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kiran,
You can download JLS from this link:
http://java.sun.com/docs/books/jls/second_edition/html/jTOC.doc.html
Ruchi.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic