If statements in C
simple if, else if, else if ladder
Size: 141.63 MB
Language: en
Added: Dec 03, 2023
Slides: 13 pages
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 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.