If else condition combine && and || in one row statement

Thank you for your time, i create some if else statement in checkbox to display result, can i combine && and || condition in one statement? for example

if (radioMale && chestPain && (leftArm || bothArm || jaw || throat)) {
highPossibilityOfHeartDisease = true;
}

User have to tick radioMale && chest pain && can tick either leftArm, bothArm, jaw or throat (one or more) to return true for highPossibilityOfHeartDisease. Is the code above valid? need some help here.

Answer

Yes you can combine && and || in a if...else statement. See it logically before considering programmatic side.

true AND true AND true AND (true OR false OR false) the condition inside brackets will be verified and set as one resulted Boolean that may be true or false according to the condition.

Then the resulting booleans will be verified linearly as normal.

You can read some articles explaining maths of boolean expressions, for example:

The Mathematics of Boolean Algebra: From StanFord University

Boolean Expressions

Boolean algebra

Leave a Reply

Your email address will not be published. Required fields are marked *