Thursday 15 March 2012

java - Better Practice: Less\greater than or equal to- OR less\greater than operator -



java - Better Practice: Less\greater than or equal to- OR less\greater than operator -

this question has reply here:

checking int within range 2 answers

which considered improve practice(if any) between using less/greater or equal to- , using less/greater operator? instance, if want test whether integer in specific range, between 5- , 10 inclusive,

if(integernumber >= 5 && integernumber <= 10){ \\do }

versus

if(integernumber > 4 && integernumber < 11){ \\do }

is 1 considered preferred practice?

edit: not asking alternative method checking numbers in range, question concerns practice of using >= <= vs > <.

regarding <= vs <, doesn't matter.

as side note, create code clearer if emulate mathematical convention:

if(a <= x && x <= b){//note how x's in middle. //do things! }

an illustration real numbers:

if(5 <= x && x <= 10){ //this much easier read. //do things! }

java

No comments:

Post a Comment