Introduction to Loops
Dr. Abu Nowshed Chy
Department of Computer Science and Engineering
University of Chittagong
Faculty Profile
Nested “For” Loop
Condition:
Nested loops consist of an outer loop with one or more
inner loops.
Outer
for(initialization; test condition; increment) loop
{ Inner
for (initialization; test condition; increment) loop
{
body of the loop
}
}
General Form
2
Pattern Print using Nested For Loop
Col. 0 Col. 1 Col. 2 Col. 3
Row. 0 (0, 0) (0, 1) (0, 2) (0, 3)
Row. 1 (1, 0) (1, 1) (1, 2) (1, 3)
Row. 2 (2, 0) (2,1) (2, 2) (2, 3)
Row. 3 (3, 0) (3, 1) (3, 2) (3, 3)
3
Display Star Square
Output:
4
Display Star Square
Program:
Outer
loop
Inner
loop
5
Display Star Square Boundary
Output:
6
Display Star Square Boundary
Program:
7
Practice Program#1
Write a C program to display the following
pattern for a given row and column input.:
8
Practice Program#1
Write a C program to display the following
pattern for a given row and column input.:
9
Display Right Triangle
Output:
10
Display Right Triangle
Program:
11
Display Inverted Right Triangle
Output:
12
Display Inverted Right Triangle
Program:
13
Display Star Pyramid
Output:
14
Display Star Pyramid
Program:
Outer
loop
Inner
loop 1
Inner
loop 2
15
Practice Task (Nested Loops)
Program: Display left triangle
Output:
16
Practice Task (Nested Loops)
Program: Display inverted left triangle
Output:
17
Practice Program#1
Write a C program to display the following
pattern for a given row and column input.:
18
Practice Program#1
19
Practice Task (Nested Loops)
[Link]
various-triangular-patterns/
[Link]
programming/examples/pyramid-pattern
20
21