Conditional Statements is using to, execute some code if a condition is true and another code if the condition is false.
Syntax (Single Line):
if (condition) Program will executed if condition is true;
Syntax (with else condition):
if (condition)
Program will execute if condition is true;
else
Program will execute if condition is false;
Syntax (with elseif and else condition):
if (first condition)
Program will execute if first condition is true;
elseif (second condition)
Program will execute if second condition is true;
else
Program will execute if all condition is false;
Syntax (with elseif and else condition separated using Curly Brackets):
if (first condition) {
Program will execute if first condition is true;
} elseif (second condition) {
Program will execute if second condition is true;
} else {
Program will execute if all condition is false;
}
Output : The value of a and b are not same.
Ternary operator :
In addition to the traditional syntax for if (condition) action ie,
ternary operator that syntax is,
(condition ? action_if_true: action_if_false;)
Output : Logical condition is false.