This document discusses control statements and functions in C programming. It describes various control statements like if/else statements, while loops, for loops, and switch statements. It also covers break, continue, and goto statements. The document then explains functions, noting that they allow programs to be broken into smaller, self-contained components and avoid repeated code. It describes function declarations and definitions. Functions can have parameters and return values or not.
2. Control Statements
Branching:
The if statement
If – Else statement
Looping:
While Statement
Do-while statement
For Statement
Switch statement
4. If – else statement
If (expr) statement1;
else
statement2;
Example:
if (status == ‘s”)
tax = 0.20 * pay;
else
tax = 0.14 * pay;
5. Nested if - else
if e1 if e2 s1
else s2
else if e3 s3
else s4
6. While statement
while (expr)
{ statement(s); }
Example: int digit=9;
while(digit <= 9)
{
printf(“%dn”, digit);
++digit;
}
7. Do – while statement
Do statement while (expr);
Example:
{
int digit = 10;
do
printf(“%dn”, digit);
while (digit <= 9);
}
8. For loop
For (expr1; expr2; expr3) statement
Example:
int I;
for (i=0;i<=10; i++) {
printf(“%d”, i);
}
9. Break statement
It can be used within a for, while , do-
while, or a switch statement.
It is used to terminate a loop or to exit
from a switch statement in a convenient
way when a condition is met, if any
error or irregular condition is detected.
10. Continue statement
It is used to bypass the remainder of the
current pass through a loop. The loop
does not terminate when a continue
statements is encountered. Rather, the
remaining loop statements are skipped
and the computation proceeds directly
to the next pass through the loop.
11. Goto statement
The goto statement is used to alter the normal
sequence of program execution by
transferring control to some other part of the
program.
goto label;
---
---
Label: statement;
12. Functions
The use of user-defined functions
allows a large program to be broken
down into a number of smaller, self-
contained components, each of which
has some unique, identifiable purpose.
The C program can be modularized
through the intelligent use of such
functions.
Avoids the need of repeated
programming of the same instructions.
13. Types of functions
Functions with no parameters and no
return value
Functions with parameters and no
return value
Functions with parameters and with
return value.