0% found this document useful (0 votes)
39 views16 pages

2 Nested Loop

Uploaded by

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

2 Nested Loop

Uploaded by

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

Academic Session 2025-26

ODD Semester Jul-Dec 2025

INSTITUTE - UIE
Department of Engineering Foundations
Bachelor of Engineering (Computer Science & Engineering)
Subject Name: Logical Thinking & Problem Solving
Code:25CSH-107

Unit No. 2 Chapter No. 1 Lecture No.2

Topic : Loops

Faculty Name-Dr. Sheenam

E_Code - E6717

Designation-Assistant Professor
Logical Thinking
& Problem
Solving
Course Objectives
The course aims to provide a strong foundation
in problem-solving using the C programming
language.
It enhances students' programming skills by
developing logical thinking and algorithmic
problem-solving abilities
By mastering C programming concepts, students
will be able to design and implement efficient
solutions for real-world problems 2
Course Outcomes

CO No Statement

To remember the concepts related to fundamentals of C language, Algorithm/


CO1
pseudocode, Flowcharts and Problem solving

CO2 To understand the way of execution and debug programs in C language.

To apply various constructs, loops, functions to solve mathematical and scientific


CO3
problem.

CO4 To analyse the dynamic behaviour of memory by the use of pointers.

To design and develop modular programs for real world problems using control
CO5
structure and selection structure.
Scheme of Evaluation
Frequency of Final Weightage
Direct Evaluation Weightage of actual
S. No. Assessment tool in Internal
Instruments conduct Task Assessment
Unit-1 Practical 15 Marks Code-Blocks & Dev C
1 Evaluation
15 Marks Hacker Rank
2 Unit-2 Practical
Evaluation
3
Unit-3 Practical 15 Marks Code Fix problems
Evaluation / Mini
3 Project 45

Lab MST 15 Marks for one Online GDB compiler 1 per semester
4 MST 15

External Exam 40 Marks Hacker Rank 1 per semester


5
40
6 Attendance NA NA NA NA
4
• Nested Loops
• Types of Nested Loops
• Examples

CONTENTS
NESTED LOOP
• The while loop is used to repeat one or more statements while a
particular condition is true.
• In the while loop, the condition is tested before any of the
statements in the statement block is executed.
• If the condition is true, only then the statements will be executed
otherwise the control will jump to the immediate statement outside
the while loop block.
• We must constantly update the condition of the while loop.
NESTED LOOP SYNTAX

Syntax
outer_loop
{
inner_loop
{
// Inner loop statement/s
}
// Outer loop statement/s
}
There are two conditions that are given.
1. The inner loop condition gets executed only when the
outer loop condition gives the Boolean output as
True. Else the flow control directly goes out of both
Working of the loops.
2. Now coming into the execution of the inner loop, If
Nested Loop the loop condition gives a true result, then the block
of statements under that loop and the incremental
condition gets executed.
3. And in turn, if the condition gives a Boolean condition
as False, then the inner loop gives its control back to
the outer loop and again same conditions/loops gets
executed/repeated.
Program 1 of Nested do-
while loop
#include <stdio.h> Explanation:
int main() •First, we initialize the outer loop counter variable, i.e., 'i' by 1.
{ •As we know that the do..while loop executes once without
int i=1; checking the condition, so the inner loop is executed without
do // outer loop checking the condition in the outer loop.
{ •After the execution of the inner loop, the control moves to the
int j=1; update of the i++.
do // inner loop •When the loop counter value is incremented, the condition is
{ checked. If the condition in the outer loop is true, then the
printf("*"); inner loop is executed.
j++; This process will continue until the condition in the outer loop
}while(j<=8); is true
printf("\n");
i++;
}while(i<=4);
}
Program 2 of Nested for
loop
Summary
• A loop within another loop is called nested loop. C programming
language supports nesting of one loop inside another.
• We can define any number of loops inside another loop. And also have
any number of nesting level.
• Write for loop inside while loop, while inside another while etc. A
programmer nest up to 3 loops. But there is no limit of nesting in C.
• It always executes the code block at least once and furthermore as long
as the condition remains true
FAQ
Q1 Print the pattern
#include<stdio.h>
int main()
{
int i,j;
for(j=1;j<=5;j++)
{
for(i=1;i<=j;i++)
printf("%5d",i);
printf("\n\n");
}
for(j=4;j>=1;j--)
{
for(i=1;i<=j;i++)
printf("%5d",i);
printf("\n\n");
}
return 0;
}
FAQ
Q2 Print the reverse pattern
#include<stdio.h>
int main()
{
int i,j;
for(j=5;j>=1;j--)
{
for(i=j;i>=1;i--)
printf("%5d",i);
printf("\n\n");
}
return 0;
}
References
Book References:
1. http://www2.cs.uregina.ca/~hilder/cs833/Other%20Reference%20Materials/The%20C
%20Programming%20Language.pdf
2. http://www.freebookcentre.net/programming-books-download/The-Basics-of-C-
Programming.html
Video Lecture:
3. https://study.com/academy/lesson/nesting-loops-statements-in-c-programming.html
4. https://www.youtube.com/watch?v=mZqo8KDR37U
5. https://nptel.ac.in/courses/106/104/106104128/

Websites:
6. https://www.studytonight.com/c/programs/loop/nested-loops
7. https://www.tutorialspoint.com/cprogramming/c_nested_loops.html
Class-wise feedback
THANK YOU

You might also like