Est 102 Control Flow
Est 102 Control Flow
CONTROL STATEMENTS
• return
Program Control
Statements/Constructs
Selection/Branching Iteration/Looping
if-else-
if if-else
if
switch break continue goto
OPERATORS
<
! >
!= ==
Operators
<=
||
>=
&& !=
RELATIONAL Equality and Logical
OPERATORS Operators
Negation !
POINTS TO NOTE
If an expression, involving the relational operator, is true, it is given
a value of 1. If an expression is false, it is given a value of 0.
Similarly, if a numeric expression is used as a test expression, any
non-zero value (including negative) will be considered as true, while
a zero value will be considered as false.
NOT AND OR
(!) operator && operator || operator
Operators Associativity
() ++ (postfix) -- (postfix) left to right
+ (unary) - (unary) right to left
++ (prefix) -- (prefix) * / % left to right
+- left to right
< <= > >= left to right
== != left to right
&& left to right
|| left to right
?: right to left
=+=-=*=/= right to left
, (comma operator) left to right
Selection Statements
Multi-way decisions
stmtT
if(TestExpr) TestExpr
stmtT;
else
stmtF;
stmtT stmtF
Algorithm C Program
1. START #include <stdio.h>
2. PRINT “ENTER THREE int main()
NUMBERS” {
int a, b, c, max;
3. INPUT A, B, C printf(“\nEnter 3 numbers”);
4. MAX=A scanf(“%d %d %d”, &a, &b, &c);
5. IF B>MAX THEN MAX=B max=a;
if(b>max)
6. IF C>MAX THEN MAX=C max=b;
7. PRINT “LARGEST if(c>max)
NUMBER IS”, MAX max=c;
printf(“Largest No is %d”, max);
8. STOP
return 0;
}
if(TestExpr1)
switch(expr)
stmtT1; {
else if(TestExpr2) case constant1: stmtList1;
stmtT2; break;
else if(TestExpr3) case constant2: stmtList2;
break;
stmtT3;
case constant3: stmtList3;
.. . break;
else if(TestExprN) ………………………….
stmtTN; ………………………….
else default: stmtListn;
}
stmtF;
TestExpr
TestExpr2
TestExpr3
stmtT1
stmtT2 TestExprN
stmtT3
stmtTF
stmtTN
while statement is a
Expanded SyntaxThe
pretest loop. of “while”
basic and
its Flowchart
syntax of theRepresentation
while
statement is shown below:
“return” statements
“break” statements
“continue” statements
break continue
1. It helps to make an early 1. It helps in avoiding the
exit from the block where it remaining statements in a
appears. current iteration of the loop
and continuing with the next
Iteration
2. It can be used in all control 2. It can be used only in loop
statements including switch constructs.
construct.