## DEV Community 👩‍💻👨‍💻 is a community of 963,864 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Greg Ross

Posted on • Updated on

# Conditional Logic

Computer science concepts in my words.

## If this, then that

Evaluating data based on a defined reason either allows the information to undergo additional computation or bypasses that circumstance until a certain condition is met or else. Pun intended.

``````if (condition) {
run code
}
``````
``````if (condition) {
run code
} else {
run code
}
``````

### Checks

Maintaining sanity in a chain of commands starts with prioritizing the most important first. The data can be cascaded from one block to another until nothing checks true.

``````if (condition) {
run code
} else if (other condition) {
run code
} else if (other condition 2) {
run code
} else {
run code
}
``````

## Statements

The conditions that are checked are evaluated based on the expressions stated. An oversimplification would be a simple yes or no. Meaning true or false. Yes you can pass or no do not pass.

``````boolean lessThan = a < b;
boolean lessThanOrEqual = a <= b;

boolean greaterThan = a > b;
boolean greaterThanOrEqual = a >= b;

boolean equal = a == b;
boolean notEqual = a != b;
``````

### More Complex

In addition to a daisy chain of if/else blocks. The conditions being evaluated can be intrinsically linked together and complicated.

``````int ohThis = 7;
int that = 13;

boolean and = (ohThis == 7 && that == 13);
boolean or = (ohThis == 7 || that == 13);

boolean isTrueAndTrue = (ohThis >= 10 && ohThis <= 15) && (that >= 10 && that <= 15);
boolean isTrueOrFalse = (ohThis >= 10 && ohThis <= 15) || (that >= 10 && that <= 15);
``````