Professional Documents
Culture Documents
LOOPING
Programming languages for Bioinformatics
BIF507
By Neeru Redhu
CCS HAU, Hisar
C language possess such decision making capabilities
by supporting the following statements
if statement
switch statement
Conditional operator statement
goto statement
2
DECISION MAKING WITH IF STATEMENT
Used to control the flow of Entry
execution of statements
if (test expression)
Test False
Expression
?
True
3
Different forms of if statements
Simple if statement
if..else statement
Nested if..else statement
else if ladder
4
SIMPLE IF STATEMENT
Entry
Single statement block
May contain multiple
statements Test True statement -
Expres block
sion ?
if ( test expression )
{ False
statement - block;
} statement -
x
Statement - x;
Next
statement
5
..
..
if ( category == SPORTS)
{
marks = marks + bonus_marks;
}
printf ( %f , marks);
..
..
6
IF..ELSE STATEMENT
if ( test expression )
{
True statement - block;
}
else
{
False statement block;
}
Statement - x;
7
Entry
statement -
x
8
NESTED IF..ELSE STATEMENT
Series of decision to made
if ( test expression 1 )
{
if ( test expression 2 )
{
statement block 1;
}
else
{
statement block 2;
}
}
else
{
statement block 3;
} 9
Statement - x;
Entry
False Test
True
Expressi
on 1 ?
statement 2 statement 1
statement 3
statement
-x
10
ELSE IF LADDER
Multipath decisions
if ( condition 1 )
statement 1;
else if ( condition 2 )
statement 2;
else if ( condition 3 )
statement 3
else if ( condition 4 )
statement 4;
else
statement 5;
statement x;
11
Entry
statement
3
statement
4
12
statement - x
SWITCH STATEMENT
Test the value of given variable (or expression) against
the list of cases values
switch (expression )
{
case value-1:
block -1;
break;
case value-2:
block -2;
break;
..
..
default:
defalut block;
break;
} 13
Statement - x;
.
.
index = marks / 10;
switch (index )
{
case 10:
case 9:
case 8:
grade = Honours ;
break;
case 7:
case 6:
grade = First Division ;
break;
case 5:
grade = Second Division ;
break;
default:
grade = Fail ;
break;
} 14
printf ( %s\n, grade);
TERNARY OPERATOR ( ? : )
15
GOTO STATEMENT
For branching unconditionally
While statement
Do statement
For statement
18
LOOPING PROCESS
Setting and initialization of conditional variable
19
WHILE STATEMENT
entry controlled loop
20
sum = 0;
n = 1; Initialization
21
DO STATEMENT
exit controlled loop
do
{
body of loop
}
while (test condition)
22
sum = 0;
n = 1; Initialization
do
{
sum = sum + n*n;
n +=1; Incrementing
}
Testing
while ( n >= 10)
printf ( sum = %d\n , sum);
23
FOR STATEMENT
entry controlled loop
24
sum = 0;
25
END
26