• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!