Professional Documents
Culture Documents
BCAC101
1 Lecture :: 15
Contents
Nested Loop
Hands On Example
2
Nested Loop
If a loop exists inside the body of another loop, it's called a nested
loop.
Any number of loops can be defined inside another loop, i.e., there
You can define any type of loop inside another loop; for example,
The nested for loop means any type of loop which is defined inside
the 'for' loop.
The nested while loop means any type of loop which is defined
inside the ‘while' loop.
while(condition)
{
while(condition)
{
// inner loop statements.
}
// outer loop statements.
8 }
Continue…
* do {
printf(" * ");
**
j++;
***
}while(j<=i);
#include<stdio.h>
i++;
#include<conio.h>
printf("\n");
void main() Output
}while(i<=r);
{
getch();
int r,i=1,j;
}
clrscr();
printf("\nEnter the row:");
12 scanf("%d",&r);
Continue…
* j++;
}while(j<=r-i+1);
**
k=1;
***
do {
#include<stdio.h>
printf(" * ");
#include<conio.h>
k++; Output
void main() {
}while(k<=i);
int r,i=1,j,k;
i++;
clrscr();
printf("\n");
printf("\nEnter the row:");
}while(i<=r);
scanf("%d",&r);
getch();
13 do {
}
j=1;
Hands On Example
15