If Else Statement
If Else Statement
1) What is if-statement?
> The if statement allows you to conditionally execute a block
of code based on a specified condition. The syntax typically
follows:
if (condition) {
// Code to execute if the condition is true
}
int main() {
int x = 10;
if (x > 5) {
return 0;
}
2) Nested-if-else statement?
> Nested if-else statements in programming involve
placing one or more conditional statements inside one
another. This allows for more complex scenarios to be
handled based on multiple conditions.
Example:-
#include <stdio.h>
int main() {
int x = 10;
int y = 5;
if (x > 5) {
printf("Outer condition is true\n");
if (y > 3) {
printf("Inner condition is also true\n");
} else {
printf("Inner condition is false\n");
}
} else {
printf("Outer condition is false\n");
}
return 0;
}
3) Execution:-
3) If-else statement?
> The if-else statement allows you to conditionally
execute a block of code based on a specified condition. The
basic syntax of the if-else statement in C is as follows:
if (condition) {
} else {
Example:-
#include <stdio.h>
int main() {
int x = 10;
// If-else statement in C
if (x > 5) {
} else {
}
return 0;
4) Else-if Ladder?
> The else-if ladder in programming is a structure that
allows the evaluation of multiple conditions in sequence,
providing a series of choices for the program to follow. It
is an extension of the if-else statement, enabling
more than two possible outcomes. Here are the key
points and an example:-
1)Syntax:-
if (condition1) {
} else if (condition2) {
} else if (condition3) {
else {
Example:-
#include <stdio.h>
int main() {
int x = 10;
if (x > 15) {
} else if (x > 5) {
printf("x is greater than 5 but not 10\n");
} else {
printf("x is 5 or less\n");
}
return 0;