{
LOOPING IN C-
PROGRAMMING
PRESENTED BY :
AFANJI PHILL MUKETE
BUWAGA RYAN ARREY
NWANKO FORGIVE
FUHNWIE HILLSON NGWASIRI
BALALA OLIVIER
At the end this presentation, you should be able to:
 Define a looping as concern C-programming
 Why we loop in C-programming
 Advantages of looping
 Types of C loops
 Essential components of a loop
 Discuss on While loop and examples
 Discuss on Do loop and examples
 Discuss on the For loop and examples
 Draw flowchart for the various types of looping in
C-programming
OUTLINE
 The looping can be defined as repeating the same
process multiple times until a specific condition
Satisfies or is true. The sequence of statements to be
executed is kept inside the curly bracket { }known as
loop body , condition is verified, and if it is found to
be true the loop body is executed again. And when
the condition check false, the loop body is not
executed
WHAT IS LOOPING IN C-
PROGRAMMING?
 Looping simplifies the complex problems into the
easy ones.
 Looping enables to alter the flow of the program so
that instead of writing the same code again and
again, we can execute the same code for a finite
number of times.
 For example, if we need to print “UNIVERSITY OF
FOMIC POLYTECHNIC” 15-times then, we can use
the Printf once inside a loop which runs up to 15
iterations.
Why we loop in C-Programming ?
 It provides codes reusability.
 Using loops we do not need to write the same
code again and again.
 Using loops, we can access each elements
stored in the array so that the data can be
checked or used as part of the process. data
structure (array is a series of memory location
which holds a single item of data).
Advantages of looping in C-
Programming
There are three types of loops in C language those
are given below;
 While
 Do while
 For
Types of C Loops
 Counter
 Initialization of the counter with initial value
 Condition to check with the optimum value of the
counter
 Statement(s) to be executed by iteration
 Increment/decrement
Essential components of a loop
 Thewhileloopincistobeusedinthescenariowhere
theblockofstatementsisexecutedinthewhileloopuntil
theconditionspecifiedinthewhileloopissatisfied.Itisalso
calledapre-testedloop.
 Thesyntaxofwhileloopinclanguageisgivenbelow:
initialization;
While(condition)
{
blockofthestatementstobeexecuted;
increment;
}
While loop in C
 Thedo-whileloopcontinuesuntilagivencondition
satisfies.Itisalsocalledposttestedloop.Itisusedwhenitis
necessarytoexecutetheloopatleastonce(mostlymenu
drivenprograms).
 Thesyntaxofdo-whileloopinclanguageisgivenbelow;
do
{
codetobeexecuted;
}
While(condition);
Do-while loop in C
• TheforloopinC languageisusedtoiteratethe
statementsorapartoftheprogramseveraltimes.It
isfrequentlyusedtotraversethedatastructureslike
thearrayandlinkedlist.
•Thesyntaxofforloopinclanguageisgivenbelow:
for(expression1;Expression2;Expression3)
{
codestobeexecuted;
}
For loop in C
 Expression 1 (Optional)
• Representstheinitializationoftheloopvariable.
•Morethanonevariablecanbeinitialized.
 Expression 2
•Expression2isaconditionalexpression.Itchecksfora
specificconditiontobesatisfied.Ifitisnot,theloopis
terminated.
•Expression2canhavemorethanonecondition.However,
theloopwilliterateuntilthelastconditionbecomesfalse.
Otherconditionswillbetreatedasstatements.
 Expression3
• Expression 3 is increment or decrement to update
the value of the loop variable
 Flowchart : For the or loop
{
Example of While loop print even numbers
1. //print even numbers
2. #include<stdio.h>
3. int main ( )
4. {
5. int n, i=0;
6. printf (“/n Enter a number : “) ;
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
Example of a DO-while loop
Example of a For Loop in C
LOOPING IN C- PROGRAMMING.pptx

LOOPING IN C- PROGRAMMING.pptx