Professional Documents
Culture Documents
PROGRAMMING
PRESENTED BY :
{
AFANJI PHILL MUKETE
BUWAGA RYAN ARREY
NWANKO FORGIVE
FUHNWIE HILLSON NGWASIRI
BALALA OLIVIER
1
OUTLINE
At the end this presentation, you should be able to:
Define a looping as concern C-programming
Advantages of looping
Types of C loops
C-programming
2
WHAT IS LOOPING IN C-
PROGRAMMING?
Do while
For
6
Essential components of a loop
Counter
Initialization of the counter with initial value
counter
Statement(s) to be executed by iteration
Increment/decrement
7
While loop in C
The while loop in c is to be used in the scenario where
the block of statements is executed in the while loop until
the condition specified in the while loop is satisfied. It is also
called a pre-tested loop.
The syntax of while loop in c language is given below:
initialization;
While(condition)
{
block of the statements to be executed ;
increment;
8
}
Do-while loop in C
The do-while loop continues until a given condition
satisfies. It is also called post tested loop. It is used when it is
necessary to execute the loop at least once(mostly menu
driven programs).
The syntax of do-while loop in c language is given below;
do
{
code to be executed ;
}
9 While(condition);
For loop in C
• The for loop in C language is used to iterate the
statements or a part of the program several times. It
is frequently used to traverse the data structures like
the array and linked list.
• The syntax of for loop in c language is given below:
for(expression 1; Expression 2; Expression 3)
{
codes to be executed;
}
10
Expression 1 (Optional)
• Represents the initialization of the loop variable.
• More than one variable can be initialized.
Expression 2
12
Example of While loop print even numbers
1. //print even numbers
2. #include<stdio.h>
3. int main ( )
4. {
5. int n, i=0;
{
7. scanf(“ % d” ,&n);
8. while ( i < = n )
9. {
10. if ( i % 2= =0)
11. printf (“/n%d” , i ) ;
12. i + +;
13. }
14. return 0
13
Example of a DO-while loop
14
Example of a For Loop in C
15
16