Decision making and Branching


Decision making

Decision making is a procedure of executing one or more statement(s) depending on the truthfulness / falsity of one or more statement.

DECISION MAKING:

1)      Branching: one or more statement(s) will be executed only once.(using if…else, switch…case, goto…label)
2)      Looping: Statements will be executed for several times.

Use of if else:

1)      By using only ‘if’ –
if(condition)
{
        Statements;
}

This is also known as unidirectional branching.
2)      By using ‘if … else’ –
if(condition)
{
        Statements;                       //if the condition is true
}
else
{
        Statements;                       //if the condition is false
}

Flowchart of ‘if…else’ statement:

This is known as bidirectional branching.
3)      By using ‘if…else…if…else’
When multiconditional branching has been to be implemented, we use ‘if…else if…else’ construct.

Let, n conditions c1,c2,c3…upto Cn are given.
if(C1)
{
        Statements;
}
else if(C2)
{
        Statements;
}
else if(C3)
{
        Statements;
}
.
.
.
else     // Cn will automatically considered as true when C1,C2…,Cn-1 has                   //become false 
{
        Statements;
}

4)      By using nested if …else
Powered by Blogger.