|
|
|
|
|
by hotBacteria
2604 days ago
|
|
You can write it without resorting to one-line conditionals: if(cond1){
myVar = 1;
}
else if(cond2 && cond3){
myVar = 10;
}
else if(cond2 && !cond3){
myVar = 100;
}
else {
myVar = 4;
}
But when I encounter this kind of situations I have other problems than code formatting anyway:with 3 conditions you have 2^3 possibilities to check: are you really really sure (!cond1 && !cond2 && cond3) should give you defaultValue ? Do you really want 1 even if !cond2 ? etc... When possible these conditions should be avoided in the first place (depending on context of course) |
|