This content originally appeared on DEV Community and was authored by Greg Ross
Computer science concepts in my own 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 this = 7;
int that = 13;
boolean and = (this == 7 && that == 13);
boolean or = (this == 7 || that == 13);
boolean isTrueAndTrue = (this >= 10 && this <= 15) && (that >= 10 && that <= 15);
boolean isTrueOrFalse = (this >= 10 && this <= 15) || (that >= 10 && that <= 15);
This content originally appeared on DEV Community and was authored by Greg Ross

Greg Ross | Sciencx (2021-11-03T03:58:15+00:00) Conditional Logic. Retrieved from https://www.scien.cx/2021/11/03/conditional-logic/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.