Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Sybex CSG 11 - chapter 4 - exercise 6

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On chapter 4 - exercise 6 on answer has a mention to an else wich is not in the sample code.
There is two atachment as evidence.

Thanks.
And sorry if I'm wrong.
ex6.PNG
[Thumbnail for ex6.PNG]
resp6.PNG
[Thumbnail for resp6.PNG]
 
Bartender
Posts: 3736
39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think here "else" is used as a synonym to "otherwise", not the part of the "if-else" construct.
 
Santiago Lovera
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok! Thanks for the answer.

But count with post increment wont be always executed? It's not the case of otherwise I think.
As this if without brackets the space line statment that will be executed in case of positive evaluation of the if.
 
Saloon Keeper
Posts: 1728
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The conditional expression is always evaluated, regardless.

There is code that will be executed if the conditional expression evaluates to true.

Because that code is either break or continue,  it is not true that the code with the post-increment will be executed regardless of the value of the conditional expression -- if the code that went with the if was almost anything else, it would be as you describe, but clearly that code is control-flow code in the form of break or continue, so -- no.
 
Jesse Silverman
Saloon Keeper
Posts: 1728
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe that the explanatory material misuses the term "conditional expression".

I don't have time to go into it further, but from section 15.25 of the JLS, we see:

JLS 17 wrote:There are three kinds of conditional expressions, classified according to the
second and third operand expressions: boolean conditional expressions, numeric
conditional expressions, and reference conditional expressions.



The conditional expression is evaluated each time.
The code that is tied to that expression by if ( condExpr ) is conditionally executed, but that code is not part of the conditional expression itself.

Someone with a bit more time right now can confirm if this could be better worded to be consistent with established terms as used in the JLS -- I suspect it could be.


 
Santiago Lovera
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks to all!!!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic