if(condition1 || condition2 || condition3){
//do something here--
}
Is there a way to check which condition returned TRUE to --do something here--
if(condition1 || condition2 || condition3){
//do something here--
}
Is there a way to check which condition returned TRUE to --do something here--
You're not supposed to be concerned about which of this three conditions returned true, otherwise it would mean that you need to use nested if statements (but apparently you don't want that).
You could either print the three conditions in the if-statement, but I don't see the point, or use the debugger if it has something to do with debugging.
In this case you have operators with same precedence and it should read as
if( condition1 || (condition2 || condition3 ) {
}
if condition1 is true then condition2 and condition3 won't be checked.
If you want to know which condition exactly evaluated to true you must do an if else statement
if( condition1 )
{
// do something when cond1 is true
}
else if( condition2 )
{
// do something when cond2 is true
}
else if( condition3 )
{
// do something when cond3 is true
}
You could make each condition a method, and then in each method registering what the condition results in before returning.