Presentation
on
Different loops in C
1
Dhaka International University
Dhaka International University
Presented By-
Md. Arif Hossain
Department of EETE (Evening)
Batch- 31st
Roll No- 33
Reg. No- EE-E-15-31-101055
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
Dhaka International University
Output:
************
*
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
Dhaka International University
Output:
Done Before?
Done Before??
Not Sure!
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
Dhaka International University
Output:
Done Before?
Done Before??
Done Before???
Not Sure!
11
Dhaka International University
12
Dhaka International University
13

Different loops in C

  • 1.
    Presentation on Different loops inC 1 Dhaka International University
  • 2.
    Dhaka International University PresentedBy- Md. Arif Hossain Department of EETE (Evening) Batch- 31st Roll No- 33 Reg. No- EE-E-15-31-101055 2
  • 3.
    Content  What isProgramming?  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
  • 7.
  • 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
  • 9.
    Dhaka International University Output: DoneBefore? Done Before?? Not Sure! 9
  • 10.
    do/while loops do{ Statementsequence; } 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
  • 11.
    Dhaka International University Output: DoneBefore? Done Before?? Done Before??? Not Sure! 11
  • 12.
  • 13.

Editor's Notes

  • #7 Variant control, when exit, repeated control
  • #9 Variant control, when exit, repeated control
  • #11 Variant control, when exit, repeated control