Win a copy of Head First Go this week in the Go 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

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!