mercredi 13 juillet 2016

Better approach for too many if else statement

if ( x < 275 && x >= 0 ) 
   f = 275
else if ( x < 450 && x >= 275) (right side comparison always previous left side default comparison value
   f = 450
else if ( x < 700 && x >= 450) 
   f = 700
else if ( x < 1000 && x >= 700) 
   f = 1000
..... and more 

is there any way or mathematical formula approach to eliminate this multiple if else statement for less code require?

Aucun commentaire:

Enregistrer un commentaire