If statements in C

MeghaSharma504 124 views 13 slides Dec 03, 2023
Slide 1
Slide 1 of 13
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13

About This Presentation

If statements in C
simple if, else if, else if ladder


Slide Content

Branching Structure If If else Else if ladder Nested if else

Four decision making statement

If statement It is generally used when we want to check a single condition. Syntax: if (condition) { Statement ; } START if (condition) Statement END False True

If else statement If the given condition is true, then the “if” block of code will be executed, otherwise “else” block of code will be executed. Syntax: if (condition 1) { Statement 1; } else { Statement 2; } START If (condition) Statement 1 True False Statement 2 END

Else-if ladder statement The “else if” ladder is used to test set of conditions in a sequence. It is also considered as multi-way decision making statement. Number of conditions are given in a sequence with subsequent statements. If any of the given condition is satisfied then the related statements are executed and the control exits from the else if ladder. That means further conditions are not going to checked. If the condition does not satisfy then the compiler goes to next condition to check the condition.

Else-if ladder statement Syntax: if (condition 1) { Statement 1; } else if ( condition 2) { Statement 2; } - - - - - - - - - - else if (condition n) { Statement n; } else { Statement m; }

Else-if ladder statement START If (condition1) If (condition n) If (condition2) False Statement 1 True END True Statement 2 False True Statement n False Default Statement

Nested if-else statement Writing if statement inside another is known as nested if. While writing number of conditions, we may need to nest if statement inside another if statement.

THANK YOU