CM304
CM304
CM304
ANDHRA PRADESH
Name of the faculty : G. Padmanabhaiah
Designation : HCME
Branch : Computer Engineering
Institute : V.K.R & V.N.B Polytechnic, Gudivada
Year/Semester : III Semester
Subject : UNIX & C.
Subject Code : CM-304
Topic : Understand repetitive structure.
Duration : 50 Min
Sub Topic : Different iterative loops.
Teaching Aids : Diagram and animations, PPTs.
CM304.50 1
Objective
CM304.50 2
Recap
while Loop:
while loop is a Top tested loop and its minimum
iterations for while is ‘0’.
CM304.50 3
do while loop
loop is ‘1’.
CM304.50 4
General form of the do while
do
{
body of the loop;
}
while (condition);
CM304.50 5
Flowchart
Enter the do statements
Execute statements
after do statements
Test
Exit from do loop
conditio False
n
True To execute
statements
CM304.50 6
Simple program using do while loop
#include<stdio.h>
main()
{
int i;
i=0;
do
{
printf (“%d\n”,i); This is body of the loop
i=i+1;
}
while(i<=10);
}
This is
condition
CM304.50 7
Differences between while and do-while
WHILE DO-WHILE
Condition is Condition is checked
checked before after entering into the
entering into the loop.
loop.
It is top tested It is bottom tested
loop. loop.
Minimum iteration Minimum iteration is
is zero. one
CM304.50 8
for loop
CM304.50 10
Flowchart Enter the for loop
Initializing statements
Evaluate
Exit the for loop
the
statemen
t
loop
Execute the statements
CM304.50 11
Simple program using for loop
#include<stdio.h>
Increment/
main() initialization decrement
{
int i;
for (i=0;i<=10;i++)
{
Body of the printf (“%d\n”,i);
loop This is
} condition
}
CM304.50 12
Summary
CM304.50 13
Quiz
CM304.50 14
Quiz
CM304.50 15
Quiz
CM304.50 16
Quiz
CM304.50 17
Quiz
3. int a=1;
while (a)
{
printf (“%d”, a);
a- -;
continue;
}
CM304.50 18
Quiz
3. int a=1;
while (a)
{
printf (“%d”, a);
a- -;
continue;
}
What is output of above program?
a) prints nothing
b) prints 1
c) prints infinite values
CM304.50 19
Quiz
CM304.50 22