The if statement is a decision making statement. It is used to manage the flow of execution of the statements and additionally used to check logically whether the condition is true or false. The If-else statement is essentially two way declaration and usually used in conjunction with condition. It is used to manage the flow of execution and additionally used carry out the logical test and then pick up one of the two feasible moves depending on the logical test. If a condition is true, then perform an action; else perform a different action.
Step-by-step explanation:
The if statement :
If the condition is true, then the true statements are executed. The true statements are may be a single statement or group of statements. If the condition is false then the true statements are not executed, instead of the program skip fast. The condition is given by relational operator like = =. ! =, < =, > =, etc.
Syntax :
if (condition is true)
{
True statements;
}
The if-else statement :
If there is only one statement in the if block or else block, then the braces are optional. But if there is more than one statement the braces are compulsory.
Syntax :
if(condition)
{
True statements;
}
else
{
False statements;
}