Upload
neel-shah
View
281
Download
0
Embed Size (px)
Citation preview
Made By:Neel Pradip Shah (13CP612)(130110107048)
1
There are some situations where one may have to
Change the order of execution based on certain conditions
OR Repeat a group of statements until certain
conditions are satisfied.
2
For this, C supports some statements which are capable of decision making, they are:
1. If statement2. Switch statement3. Conditional Operator4. Goto Statement5. While loop6. Do-While loop7. For loop
3
Syntax
if(test expression){
statement Block;
} statement X;
Test expression ?
Statement - block
Statement - X
Next Statement
TRUE
FALSE
ENTRY
4
Syntax
if(test expression){ statement
Block(true);}else{ statement
Block(false);} statement X;
Test expression ?
Statement - block
Statement - X
TRUE
ENTRY
Statement - block
FALSE
5
Syntax
switch(expression){ case value-1: block-1; break;case value-2: block-2; break;……………..……………..default block; break;}Statement - X
6
It is used for an unconditional jumpSyntax(forward jump) (backward jump)goto label; label:…………….. Statement;…………….. ………………Label: ………………Statement; goto label;
Programmers avoid using this As this statement makes logic complicated and
debugging is difficult.
7
An Entry Controlled loop
Syntax while(test condition){
Body Of the Loop }
8
An Exit Controlled loop
Syntaxdo{
set of statements}while(condition);
9
An Entry Controlled Loop
Syntax
for(initialization ; test-condition ; increment) {
BODY OF THE LOOP }
10
for(initialization ; test-condition ; increment)
{
BODY OF THE LOOP
}
11
Entry
True
False
Entry
False
True
Test Condition
Test Condition
Body of The loop
Body of The loop
12
a=10; for(a=10; a!=0; a--)a=10; for(a=10; a!=0; a--)while(a != 0)while(a != 0) { {{ printf(“%d”,a);{ printf(“%d”,a);
}}printf(“%d”,a);printf(“%d”,a);
a--;a--;} }
a=10;a=10;dodo{ OUTPUT : 10987654321{ OUTPUT : 10987654321 Printf(“%d”,a);Printf(“%d”,a); a--;a--;}}while(a!=0)while(a!=0)
13
ANSI C By E.Balagurusamy Programming With C By Byron S Gottfried
14
15