As the name refers its meaning that a control structure is that which control the flow of execution.The flow of any instruction,Function,etc..There are two types of control structure.
- Decision control structure
- Counter control structure
Decision control structure
Decision control structure is defined as the control structure which depend upon certain decision.Decision control is also of two types.
- Control conditionally
- Unconditional control
Control conditionally means here that control is depend upon certain fixed condition.
Here we will discuss some of basic decision control conditionally structure which are following:-
- if control structure
- if-else control structure
- if-else-if or if-else ladder or nested if-else
- switch case control structure
If control structure
in this structure one condition is given.if the condition is satisfied then statement is executed otherwise not.There may be more than one statements.
If-else control structure
There may be a single or more than one statements.In this structure when condition is true than statement 1 and statement 3 executed,otherwise statement 2 executed.
printf("Number is even");
printf("Number is odd");
Note:-if there is single statement then we can write without braces.
If-else-if control structure
else if(condition 2)
In this control structure nested if else is used.There is follow a condition within a condition.
printf("Number is Negetive");
printf("number is even");
printf("Number is odd");
single statement used so no need to apply braces.
Switch control structure
Switch control structure is also control the flow of execution.in this different cases are made and then matches are found for execution.The switch-case statement is a multi-way decision statement. Unlike the multiple decision statement that can be created using if-else, the switch statement evaluates the conditional expression and tests it against numerous constant values. The branch corresponding to the value that the expression matches is taken during execution.
The value of the expressions in a switch-case statement must be an ordinal type i.e. integer, char, short, long, etc. Float and double are not allowed.
switch( expression )
break statement:-By this statement control is out of program.when match is found then break statement brings the control out of program otherwise all cases are tested.default case is for no match found condition which is used to avoid infinite looping which may create error.
Unconditional decision control structure:
This control structure is defined as the control structure in which there is no condition is provided for stopage. Go to statement is example of this.In this level no. is given to statement.
go to 10;
10 is here level number.Go to statement is not much used in programming because of it is uncontrolled.
So friends this is all about decision control structure.I hope You were enjoy it.