Académique Documents
Professionnel Documents
Culture Documents
{
statement(s);
}
if (Condition)
statement;
Example:
if (i > 0)
{
printf("i = %d “, i );
}
if (i > 1 || j!=5)
{
printf("i = %d “, i );
}
true
Condition?
Statement-1 false
Statement-2
Statement-3
if (condition)
{
stmt(s) for true case;
}
else
{
stmt(s) for true case;
}
Or
if (condition)
stmt for true case;
else
stmt for true case;
true
Condition?
Statement-1 false
Statement-2
Statement-3
switch (variable-name)
{
case value1:
Execute stmt1;
break;
case value2:
Execute stmt2;
break;
case valueN:
Execute stmtN;
break;
default:
Execute last;
}
-6- By: Kute T. B. for FYIF (2007-08)
switch-case flowchart
Variable
Value1 default
Value2
Next
Statement
int w = 20;
switch(w)
{
case 10: printf(“A”);
break;
case 20: printf(“B”);
break;
case 30: printf(“C”);
break;
default: printf(“D”);
}
if (x > 0)
y = 1
else
y = -1;
is equivalent to -
y = (x > 0) ? 1 : -1;
label:
statement; Backward
- - - - - - Jump
- - - - - -
- - - - - -
goto label;
e.g.
int a = 20;
while(a>10)
{
printf(“CPR”);
a--;
}
false
Condition?
Statements true
inside the loop
Statement-2
Statement-3
do
{
// Loop body;
}
while (condition is true);
Example:
int a = 0;
do
{
printf(“%d”,a);
a++;
}while(a<50);
- 13 - By: Kute T. B. for FYIF (2007-08)
do-while flow-chart
Statements
inside the loop
true
Condition?
false
Statement-2
Statement-3
Example:
int a;
for(a=0;a<10;a++)
{
printf(“\n%d”,a);
}
Or
int a;
for(a=0;a<10;a++)
printf(“\n%d”,a);
initialization
false
Condition?
Increment true
/decrement
Statements
inside the loop
Statement-2
Statement-3
false
Condition?
break true
Statements
Statement-2
Statement-3
int a = 10;
while( a >= 0 )
{
printf(“\n a = %d”,a);
a--;
if(a==5)
break;
}
Output:
Value of a = 10
Value of a = 9
Value of a = 8
Value of a = 7
Value of a = 6
false
Condition?
Statement-3 true
continue
Statement-2
Statement-4
Statement-5
int a = 6;
while( a >= 0 )
{
a--;
if(a==3)
continue;
printf(“\n a = %d”,a);
}
Output:
Value of a = 5
Value of a = 4
Value of a = 2
Value of a = 1
Value of a = 0