Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 13

Presentation

on
Different loops in C

Dhaka International University


1
Presented By-
Md. Arif Hossain
Department of EETE (Evening)
Batch- 31st
Roll No- 33
Reg. No- EE-E-15-31-101055

Dhaka International University


2
Content

 What is Programming?

 What is Structured Programming?

 What is Loops?

 Sample program using for, while & do/while loops

Dhaka International University


3
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
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
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
Output:

*****
****
***
**
*
Dhaka International University
7
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
Output:

Done Before?
Done Before??
Not Sure!

Dhaka International University


9
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
Output:

Done Before?
Done Before??
Done Before???
Not Sure!

Dhaka International University


11
Dhaka International University
12
Dhaka International University
13

You might also like