Decision Making Statements in C
Decision-making statements in C language are the same as in other programming languages such as C++, Java, etc. Decision-making is needed when you want a set of instructions to be executed in a condition and other sets of instructions in another condition.
The following are the decision-making statements in C,
if statement
If the condition is true, the statement gets executed. If the condition is false, it does nothing.
Syntax
The following is the syntax for the if statement in C language,
if-else statement
If the condition is true, then a set of statements is executed. If the condition is false, another set of statements gets executed.
Syntax
The following is the syntax for the if-else statements in C language,
You can also work on nested if-else. Let us see how we can do it for the preceding example,
else-if statement
The else-if statement is useful when if-statement has more than one condition.
Syntax
The following is the syntax for the else-if statements in C languages,
Switch Statement
Use the switch statement, if you want to take a decision from more than one choice. For example, grades A, B, C, D, E, etc based on the marks of students.
The following is an example showing the usage of the switch statement in C language,
In this lesson, we learned how to work with Decision Making Statements in C Programming. We saw how to implement if, if-else, else-if, and switch statements in C.
If you liked the tutorial, spread the word and share the link and our website LANGUAGE CODING with others.
0 comments:
Post a Comment