C - Language Theory
If...Else Statement:
if is a conditional control statement. If condition is ture then the statements inside the body of "if " are executed or then inside body of "else" are executed.
If Else Statement
If Else Statement
Syntax of If Else Statement |
---|
if(condition) { //Code to be executed if condition is true } else { //Code to be executed if condition is true } |
Nested if else statement
Nested if else statement
When an if else statement is present inside the body of another ”if” or “else” then this is called nested if else.
Syntax of Nested if...else statement |
---|
if (condition) { //Nested if else inside the body of "if" if (condition) { //Statement inside of the body of nested "if" } else { //Statement inside of the body of nested "else" } } else { //Statements inside the body of "else" } |
Else - If Statement
Else - If Statement
The else if statement is useful when you need to check multiple conditions within the program, nesting of if-else blocks can be avoided using else if statement.
Syntax of else if statement |
---|
if (condition 1) { //Code to be executed if condition 1 is true } else if (condition 2) { //Code to be executed if condition 2 is true } else { //Code to be executed if all the conditions return false } |