### Decision Control Structure

Control structure holds the execution of a program by any condition or decision. Control structure specifies the order in which the various instructions in a program are to be executed by the computer. Control structure determines the flow of control in a program.

There are 3 types of control structures:
1. Select or Decision Control Structure. Decision statement allow the computer to take a decision as which statement is to be execute next.
Decision Statement are of 2 types: a. If - if the condition is true than only the statement will be executed.

```Syntax:
if (condition)
{
Statement 1;
Statement 2;
.
.
Statement n;
}```

b. if – else - if else contain statements in 2 parts. Statement of one will execute if the condition is true other statement will execute if the condition is false. Both statements will not execute in either condition.

```Syntax:
if (condition)
{
Statement 1;            Statement execute if the condition is true
Statement 2;
.
.
Statement n;
}
else
{
Statement 1;            Statement execute if the condition is false
Statement 2;
.
.
Statement n;
}```
c. Nested if - Nested if is use when multiple if condition is use.
```Syntax:
if (condition 1)
{
Statement 1;
Statement 2;
.
.
Statement n;
}
else if (condition 2)
{
Statement 1;
Statement 2;
.
.
Statement n;
}
else
{
Statement 1;
Statement 2;
.
.
Statement n;
}```
In the above example, statement 1 is executed when condition 1 is true rest of the condition is not executed nor checked. Statement 2 is executed when condition 1 is false and condition 2 is true. If both the condition 1 and condition 2 is false than statement 3 is execute.
b. Switch case - Switch case is used where we required to make a choice between a number of alternatives.
```Switch (variable)
{
case value:
statement 1;
statement 2;
break;
case value:
statement 1;
statement 2;
break;
default:
statement 1;
statement 2;
}```
Default statement is execute when no case value if true.
2. Loops - Loops is used to repeat a block of code. They are executed upto a certain fixed number of times or upto infinity.
a. for - for loop set a loop counter to an initial value, it tests the loop counter to determine wheather the condition is true, it increase the value of loop counter each time automatically. For Loop contains 3 parts. Initialization, condition, and increment/decrement.
```Syntax:
for (initialize variable; condition; inc/dec)
{
Statement 1;
Statement 2;
.
.
Statement n;
}```
b. while loop - In which loop condition is tested before the statements are executed. Initialization is done above the while loop and increment / decrement is done inside while loop.
```Syntax
i = 1; 					// initialization
while (i<=10)			// condition
{
printf ("Hello\n");
i++;				// increment
}```
c. do while loop - do while loop is similar to while loop except in do while loop condition is tested after the statement has been executed, this means that statements in do while loop execute at least 1 time.
```Syntax:
int i=0;
do
{
i++;
printf (“Hello World”, i);
}while(i<5);
```
3. Jumping Statement - Jumping statements are generally used within a branching statement. Jumping statement are used to jumping out from any loop within its execution.
a. Break - Break statement is used to jump out from a loop at a certain point.
```Syntax:
for (i=1;i<=10;i++)
{
printf ("%d\n", i);
if(i == 5)
break;
}
```
Note: Break statement is use only inside a loop.
b. Continue - If we don’t want to write any statement inside any condition then we can use continue statement. Continue is used to skip the statements.
```Syntax:
for (i=1;i<=10;i++)
{
if (i == 10)
continue;
else
printf (“%d”, i);
}
```
c. Goto - A goto statement can be use anywhere in between the program. Goto statement transfers the control to the label.
```Syntax:
Void main ()
{
int i;
for (i=1 ; i<=10 ; i++ )
{
printf(“%d”, i );
if (i = = 5 )
goto end;
}
end:
getch();
}
Output:	1 2 3 4
```