This presentation discusses different loops in C programming. It defines programming and structured programming. It then explains the three types of loops in C - for, while, and do/while loops. Sample programs are provided to demonstrate each loop, showing how they iterate and check their loop conditions. The for loop checks at the top of the loop. The while and do/while loops can check at the top or bottom of the loop respectively.
3. Content
What is Programming?
What is Structured Programming?
What is Loops?
Sample program using for, while & do/while loops
Dhaka International University
3
4. What is programming?
Programming is the technique way to accomplish a task or to
solve a problem by using program.
What is Structured programming?
Structured programming (sometimes known as modular
Programming) is a subset of procedural programming that
enforces a logical structure on the program being written to
make it more efficient and easier to understand and modify.
Structured programming works as modules.
Dhaka International University
4
5. What is Loops?
In C and all other Programming languages, loops allow a set
of instructions to be performed until a certain condition is
reached. This condition may be predefined as in the for loop, or
open-ended as in the while and do loops.
Dhaka International University
5
6. For loops (initialization; condition; increment) statement
An important point about for loop is that the conditional test is always
Performed at the top of the loop
//A Program for a Inverted Pyramid using for loop
#include<stdio.h>
#include<conio.h>
void main ()
{
int i, j;
clrscr();
for (i=0; i<5; i++)
{
for(j=i; j<=4;j++)
printf("*");
printf("n");
getch();
}
6
8. while loops (condition) statement
for & while loops performs in the same way that means while loops
check the test condition at the top of the loop. for & while loops is called
entry controlled loops.
//A Program using while loop
#include<stdio.h>
#include<conio.h>
void main ()
{
int i=0;
clrscr();
while (i<2)
{
printf("Done Before?n");
i++;
}
printf ("Not Sure!");
getch();
}
8
10. do/while loops do{
Statement sequence;
}
while(condition);
for & do/while loops checks its condition at the bottom of the loop. Its
called exit controlled loops.
//A Program using do/while loop
#include<stdio.h>
#include<conio.h>
void main ()
{
int i=0;
clrscr();
do
{
printf("Done Before?n");
i++;
}
While (i<2);
printf ("Not Sure!");
getch();
}
10