• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to understand result of this code

 
gurneeraj singh
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

How we solve equation in line 1.

[ March 22, 2008: Message edited by: gurneeraj singh ]
 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The output will be "Mercury" and only the logic to the left of the || operator will ever be evaluated for the given boolean values.

You can read line 1 as:

if both b1 and b2 are true, execute the if-body immidiately.
OTHERWISE
if either b3 or b4 are true, or both are, execute the if-body.
OTHERWISE
execute the else body.

An equivalent if-else structure would be:


Remeber that in the abscence of parentheses the order of precendence for boolean operators is (highst priority first):
1. &
2. |
3. &&
4. ||
[ March 22, 2008: Message edited by: Jelle Klap ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic