The document provides a comprehensive overview of looping concepts in C programming, emphasizing the importance of loops for efficient coding. It covers three types of loops: while, do-while, and for, detailing their syntax and functionality. Additionally, it includes assessment metrics and references for further reading on the topic.
Course Objective
Understandthe basic terminology used in computer
programming
It stresses the strengths of C, which provide students with
the means of writing efficient, maintainable, and portable
code.
write, compile and debug programs in C language.
Increase the ability to learn new programming languages
OBJECTIVES
4.
Topic Objective
Understandthe basics of looping.
To use the while, do-while and for repetition statement to
execute statements in a program repeatedly.
5.
INTRODUCTION
Statements ina program are executed one after the other
ex: statement 1;
statement 2;
:
statement n;
Sometimes, the user want to execute a set of statements
repeatedly.
6.
Loop statementsare used to repeat the execution of
statement or blocks.
Iteration of a loop: the number of times the body of loop is
executed.
Two types of loop structure are:
Pretest : Entry - controlled loop
Posttest : Exit – controlled loop
7.
Pretest Vs. Posttest
Pretest: Condition is tested before each iteration to check
if loops should occur.
Posttest : Condition is tested after each iteration to check
if loop should continue (at least a single iteration occurs).
Conditio
n
Evaluate
d
Statements
false
true Conditio
n
Evaluate
d
Statements
true
false
while Loop
Ithas a loop condition only that is tested before each
iteration to decide whether to continue or terminate the
loop.
The body of a while loop will execute zero or more
times
Syntax:
while (<condition>){
<statement/block>;
}
do…while Loop
Dowhile has a loop condition only that is tested after
each iteration to decide whether to continue with next
iteration or terminate the loop.
Syntax:
do{
<statement/block>;
}while(condition);
for Loop
for loophas three parts:
Initializer is executed at start of loop.
Loop condition is tested before iteration to decide
whether to continue or terminate the loop.
Increment is executed at the end of each loop iteration.
14.
Syntax:
for( [initialize]; [condition];[incrementor] )
{
<statement/block>;
}
Conditio
n
Evaluate
d
initialization
Statements
increament
true false
Flow diagram
ASSESSMENT METRIC
Whatis looping? List the types of looping.
Explain the while loop with an example.
Give the difference between while and do-while loops
Explain the syntax of for loop with an example
List out the difference between while and for loop. And also
explain the do-while loop.
17.
CONCLUSION
Importance ofloops in any programming language is
immense, they allow us to reduce the number of lines in a
code, making our code more readable and efficient.
18.
REFERENCES
[1]. E. Balaguruswamy,“Programming in ANSI C”, Third
edition, Tata McGraw Hill Publications, 2002.
[2]. P. B. Kotur, “Computer Concepts and C
programming”, Kindle Edition, Sapna Book House,
Bangalore, 2009.