Whenever we build an application in any programming language, there is a need of including decision control statements in code. We can include various conditions in our program using these statements, we can perform different- different tasks based on the conditions. Following are the decision control statements available in C.
a) if statement
b) if-else & else-if statement
c) switch-case statements
Below are the tutorials links –
- If statement: The code inside if body executes only when the condition defined by if statement is true. If the condition is false then compiler skips the statement enclosed in if’s body. We can have any number of if statements in a C program.
- If-else statement: Here, we have two block of statements. If condition results true then if block gets execution otherwise statements in else block executes. else cannot exist without if statement. In this tutorial, I have covered else-if statements too.
- Switch-case statement: This is very useful when we have several block of statements, which requires execution based on the output of an expression or condition. switch defines an expression (or condition) and case has a block of statements, based on the result of expression, corresponding case gets execution. A switch can have any number of cases, however there should be only default handler.