2. 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
3. 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?
4. 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 ?
5. 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
6. There are three types of loops in C language those
are given below;
While
Do while
For
Types of C Loops
7. 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
11. 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
13. {
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