If Else Expressions Blog
A simple blog containing information concerning If and Else Statements, with DeMorgan's law.
Explaining If, If-Else, and If-ElseIf-Else
- What is an if statement?
The IF statement is a decision-making statement that guides a program to make decisions based on specified criteria. The IF statement executes one set of code if a specified condition is met (TRUE) or another set of code evaluates to FALSE
- What is an if-else statement?
The if/else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed.
- What is an if-elseif-else
It's the same thing as an if-else statement, however you can continue with the elses as different cases that execute different segments of programs.
int x = 25;
if (x>=27) {
print("This works") //One case if statement is true
} else {
print("This doesn't work sadly") //Showing different case
}
De Morgan's Law
- What is De Morgan's Law?
The complement of the union of two sets is the intersection of their complements and the complement of the intersection of two sets is the union of their complements.
In simple terms, De Morgan's laws talk about how mathematical statements are related through their opposites.
if (true) {
System.out.println("True code block");
}
if (true && !false) {
System.out.println("True and Not False code block");
}
if (true || false) {
System.out.println("True or False code block");
}
if ((true && !false) && (true || false)) {
System.out.println("Confusing code block");
}
if (!((false || !true) || (false && true))) {
System.out.println("De Morgan's law in my head of confusing code block");
}
//All these code segments can be reduced to the very first code segment. There are different ways of utilizing these types of logical operators in order for a program to run.