Please check the code below
if( x > 10 && x <= 100 ){
do.something(1)
}
else if ( x > 100 && x <= 1000 ) {
do.something(2)
}
else if ( x > 1000 && x <= 10000 ) {
do.something(3)
}
else if ( x > 10000 && x <= 100000 ) {
do.something(4)
}
- Is the any better alternative to this if/else or switch chain?
- Can we make it configurable - so that I can keep all the conditions and corresponding action in one data-structure and write code that can pick all the conditions from that structure and do actions accordingly? This will help me keep all the conditions in a separate conf file and it will be easy to just make the edits to that and not touch the code
NOTE: These ranges may be inconsistent like 100 - 200, 345 - 956, 1000 - 1200