Deicision Making and Branching
We have seen that programs are some set of statements written in a specific order. Processor will executed the programs in the order in which it was written. We may come to a situation where we need to alter the sequential execution of the statements to achieve some results. We may need to take some decisions based on the needs of the context for which the program was written and will branch or alter the execution of statements accordingly. For example, if we are preparing a students results publishing program, then we may need to take decision on whether a student is passed or not. If a student gets a specified minimum mark or more he is passed otherwise he is failed, this is a simple kind of decision making, we will implement this in C programs using the some decision making/branching control structures and conditions.
Conditions are tested for its truth values and if the condition is true then it will execute some statements, if the condition is false it will execute some other statements or will check another condition for its truth values. C supports 4 different decision making statements and are commonly used in all other programming languages.
Decision making statements in C
- If statement
- Switch statement
- Conditional Operators
- Goto statement
Among the 4 decision making statements, If, Switch and Conditional operators are supported by most of the programming languages. Goto statement is a branching statement and is not commonly used in many programming languages and in C itself usage of goto statement is not recommended. Goto statements where the constructs used in the unstructured programming languages for branching and present languages like C, C++, Java etc. possesses structured feature and it follows Sequential, Conditional and Iteration statements in its programs.



0 comments:
Post a Comment