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

If doubt

 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read from JLS the following quote...
--------------------------------------------------
14.7 Statements are thus gramatically divided into 2 categories: that which might end in an if statement that has no else block(short if statement) and those that definitely do not.Only those that definitely do not end in a short if statement may appear as an immeadiate substatement
before the keyword else in an if statement that does not have an else clause
-------------------------------------------------

Am confused about this
Can someone help please
Thanks
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused because I can't find this in the JLS. 14.7 deals with labeled statements. Do you have a link so I can see this in context?
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found it... it's actually 14.5.

"Only statements that definitely do not end in a short if statement may appear as an immediate substatement before the keyword else in an if statement that does have an else clause."
We see in the above example a violation of the statement above. The sub-if is trying to be a short-if but it can't because the the main-if's else statement gets assigned to the short if. In other words the above code gets turned into:

The solution around this problem is the proper use of braces to identify where the if-else statements belong.
 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sorry.. it is under 14.5 in the chapter "Blocks and Statements" under the heading "Statements" in the last before paragraph...
Thanks.
 
sun par
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Thomas..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic