• 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!