This week's book giveaways are in the Scala and Android forums.
We're giving away four copies each of Machine Learning Systems: Designs that scale and Xamarin in Action: Creating native cross-platform mobile apps and have the authors on-line!
See this thread and this one for details.
Win a copy of Machine Learning Systems: Designs that scale this week in the Scala forum
or Xamarin in Action: Creating native cross-platform mobile apps in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

precedence  RSS feed

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the statement below given values for x and y

if ( (x>3) && (y>2) | dostuff() ) {}

is the same as

( (x>3) && ((y>2)| dostuff()) )

because | has higher precedence over &&

what if I have the statement

( (x>3) & (y>2) | dostuff() ) {}

In what order will it be evaluated?


Thanks,

vijaya
 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A search on google referred me to this page with the order of operations:


http://www.sniffer.net/bookshelf_do_sniffer/java/langref/ch04_14.htm


The & is higher in terms of precedence so the statement would be executed from left to right as is
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
( (x>3) & (y>2) | dostuff() ) {}

I think since its always from left to right the and is first evaluated then
 
Get out of my mind! Look! A tiny ad!
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!