0% found this document useful (0 votes)
12 views

Lect#12

The document discusses different types of nested loops in C programming including nested for loops, nested while loops, and nested do-while loops. Examples are provided to print number and star patterns using nested loops. Code snippets show the syntax of nested loops and implementations to print 1, 12, 123, 1234, 12345 and a star pattern using nested while and for loops.

Uploaded by

Muhammad Taimoor
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Lect#12

The document discusses different types of nested loops in C programming including nested for loops, nested while loops, and nested do-while loops. Examples are provided to print number and star patterns using nested loops. Code snippets show the syntax of nested loops and implementations to print 1, 12, 123, 1234, 12345 and a star pattern using nested while and for loops.

Uploaded by

Muhammad Taimoor
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Nested Loops

Nested for Loop


The syntax for a nested for loop statement in C is as
follows −
for ( init; condition; increment )
{
for ( init; condition; increment )
{
statement(s);
}
statement(s);
}
Nested while loop
The syntax for a nested while loop statement in C
progra
while(condition)
{
while(condition)
{
statement(s);
}
statement(s);
}
Nested do...while loop
do
{
statement(s);
do
{
statement(s);
}
while( condition );
}
while( condition );
Contd..
Write a program to print the following number
pattern.
1
12
123
1234
12345
Contd..
int i=1,j;
while (i <= 5)
{
j=1;
while (j <= i )
{ cout(j);
j++;
}
cout("\n");

i++;
}
Write a program to print the given
star pattern by using while loop.
*
**
***
****
*****
contd,..
int i=1,j;
do
{
j=1;
do
{
cout("*");
j++;
}
while(j <= i);
i++;
cout("\n");
}
while(i <= 5);
Nested for loop

Write a program to print the number pattern.


1
12
123
1234
12345
Contd..
int u,i;
for(u=1;u<=5;u++)
{
for(i=1;i<=u;i++)
cout<<i<<“\t”;
cout<<endle;
}

You might also like