0% found this document useful (0 votes)
1 views21 pages

7 - IntroductionToLoops

The document provides an introduction to nested loops in programming, specifically focusing on the structure and usage of nested 'for' loops. It includes examples of patterns created using nested loops, such as star squares and triangles, along with practice tasks for readers to implement. The content is aimed at teaching the concept of loops in C programming within a computer science context.

Uploaded by

yeameenspondon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views21 pages

7 - IntroductionToLoops

The document provides an introduction to nested loops in programming, specifically focusing on the structure and usage of nested 'for' loops. It includes examples of patterns created using nested loops, such as star squares and triangles, along with practice tasks for readers to implement. The content is aimed at teaching the concept of loops in C programming within a computer science context.

Uploaded by

yeameenspondon
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like