🌐
GeeksforGeeks
geeksforgeeks.org › c language › nested-loops-in-programming
Nested Loops in Programming - GeeksforGeeks
April 30, 2024 - In programming, Nested Loops occur when one loop is placed inside another. These loops are quite useful in day-to-day programming to iterate over complex data structures with more than one dimension, such as a list of lists or a grid.
🌐
Reddit
reddit.com › r/learnprogramming › can someone please explain nested loops / loops in general, like i'm five? (c++)
r/learnprogramming on Reddit: Can someone please explain nested loops / loops in general, like I'm five? (C++)
March 20, 2014 -

I'm in a beginner class at my high school, and I'm trying to learn programming. I find loops sort of easy to understand, but we're supposed to create a multiplication table using a nested loop and I just can't get it. Help! Thank you!

Top answer
1 of 5
7
Loops like you're 5: A loop is a way to tell the computer to do something specific repeatedly. For instance, if you were a (human) computer and I told you to walk to the end of the street and back until you have done so three times; this is a loop. It's a specific instruction done repeatedly. Loops don't always have an end. If I told you (as a computer) to walk to the end of the street and back until I tell you to stop; if suddenly I decide to move to France while you're walking back and forth, this is an example of a potential infinite loop. I may come back to visit and tell you to stop. You may keep going until you keel over. Nested loops like you're 5: If a loop is a set of specific instructions done repeatedly, what happens if you put a loop in a loop? Well, one of those loops has to finish entirely before the other can continue again. If I told you to walk down to the end of the street 3 times and back, but when you get halfway back, stop and touch your nose 5 times before you start again; this is a nested loop. You may say to yourself "but wait, I can touch my nose while I'm walking, why do I need to stop?" and you would be right, but what we need to realize about computers is that because of how they work, they can only do one thing at a time. (see below before any objections) Computers work in steps. Do A, then do B, then do C. Loops allow us to say "but do X over and over again." You may then say "but how come I can browse reddit, listen to music, and download stuff at the same time on my computer?" and this moves into the concepts of concurrency, or in simpler terms, making the computer do lots of different things at the same time. Things like this exist because we may want a loop to be indefinite, or to end when we tell it to end. Lots of things in the computer world depend on infinite loops, including browsing Reddit (for server side web services, some web browsing features) and video games (rendering and game logic loops). This is where concurrency and asynchronous operations come into play, but this is beginning to get out of the scope of the question, so I'll stop it here (unless you're interested). tl;dr
2 of 5
2
A nested loop will perform the inner loop in its entirety for each iteration of the outer loop. So if you had an inner loop of 10 with an outer loop of 3, it's going to go 1-10, 3 times.
Learning C: For Loops Aug 10, 2024
r/C_Programming
last yr.
Are nested for-loops always O(n^2)? Jun 29, 2022
r/computerscience
4y ago
How to better understand loops? Dec 13, 2021
r/learnprogramming
4y ago
Wrapping your head around loops. Jan 25, 2018
r/learnprogramming
8y ago
More results from reddit.com
Discussions

Explaining "Nested Loops" to Someone Without a Computer's Background
Looking through each row of books in a library. Outer loop looks through each row and inner loop looks at each book in that row. More on reddit.com
🌐 r/computerscience
16
0
May 29, 2022
Can someone please explain nested loops / loops in general, like I'm five? (C++)
Loops like you're 5: A loop is a way to tell the computer to do something specific repeatedly. For instance, if you were a (human) computer and I told you to walk to the end of the street and back until you have done so three times; this is a loop. It's a specific instruction done repeatedly. Loops don't always have an end. If I told you (as a computer) to walk to the end of the street and back until I tell you to stop; if suddenly I decide to move to France while you're walking back and forth, this is an example of a potential infinite loop. I may come back to visit and tell you to stop. You may keep going until you keel over. Nested loops like you're 5: If a loop is a set of specific instructions done repeatedly, what happens if you put a loop in a loop? Well, one of those loops has to finish entirely before the other can continue again. If I told you to walk down to the end of the street 3 times and back, but when you get halfway back, stop and touch your nose 5 times before you start again; this is a nested loop. You may say to yourself "but wait, I can touch my nose while I'm walking, why do I need to stop?" and you would be right, but what we need to realize about computers is that because of how they work, they can only do one thing at a time. (see below before any objections) Computers work in steps. Do A, then do B, then do C. Loops allow us to say "but do X over and over again." You may then say "but how come I can browse reddit, listen to music, and download stuff at the same time on my computer?" and this moves into the concepts of concurrency, or in simpler terms, making the computer do lots of different things at the same time. Things like this exist because we may want a loop to be indefinite, or to end when we tell it to end. Lots of things in the computer world depend on infinite loops, including browsing Reddit (for server side web services, some web browsing features) and video games (rendering and game logic loops). This is where concurrency and asynchronous operations come into play, but this is beginning to get out of the scope of the question, so I'll stop it here (unless you're interested). tl;dr More on reddit.com
🌐 r/learnprogramming
17
4
March 20, 2014
Nested for loops are really difficult for me to understand. Can anyone help me out?
There is nothing interesting about nested for loops. Nothing. NO thing. If you have a loop, you repeat the stuff in the loop body. It doesn't matter what that thing is, you repeat it. If that thing is a function call, you repeat the function call. If it's variable assignment, you repeat the variable assignment. If it's a loop, you repeat the loop for(i = 0; i <= 3; i++){ for(j = 0; j < i; j++){ System.out.print(" "); } System.out.println(i); } This is just: for(i = 0; i <= 3; i++){ doopitydo } What does this do? It repeats doopitydo 3 times (edit: 4 times. Stupid <=). That's it. What is doopitydo? Glad you asked. It's this: for(j = 0; j < i; j++){ System.out.print(" "); } System.out.println(i); So what does this do? Obviously it prints i spaces followed by the number i and then a carriage return, right? It doesn't matter that it's in a loop. It does exactly the same thing if it isn't. If all you had was: int i = 27; for(j = 0; j < i; j++){ System.out.print(" "); } System.out.println(i); Then the code would print 27 spaces and then the number 27. You can analyze the body of the loop (in almost all cases) without reference to the fact that it's in a loop, because it behaves the same way regardless of whether it's in a loop or not. Your problem is in thinking that there is something special about "loop within loop" vs "loop not within a loop". Nope. They are exactly the same. The loop repeats what's in the body of the loop. Period. It repeats it exactly the same way regardless of what is in the body. Variable assignment, function calls, other loops, loops within loops within loops within loops that call functions? None of that matters. More on reddit.com
🌐 r/learnprogramming
15
1
February 6, 2018
what practical reasons would I use a nested for loop for?
when you want to do a thing repeatedly for every time that you're also doing some other thing repeatedly? More on reddit.com
🌐 r/learnprogramming
19
0
September 18, 2016
🌐
The Linux Documentation Project
tldp.org › LDP › abs › html › nestedloops.html
Nested Loops
A nested loop is a loop within a loop, an inner loop within the body of an outer one. How this works is that the first pass of the outer loop triggers the inner loop, which executes to completion. Then the second pass of the outer loop triggers the inner loop again.
🌐
Medium
medium.com › @nathjanmjay › title-exploring-different-types-of-nested-loops-in-programming-a2e479bb28f4
Title: Exploring Different Types of Nested Loops in Programming | by Nath Janm jay | Medium
February 29, 2024 - This means that one loop is placed within the body of another loop. In programming, loops are used to execute a block of code repeatedly until a certain condition is met. When one loop is nested within another, the inner loop will execute its ...
🌐
Mimo
mimo.org › glossary › programming-concepts › nested-loops
Nested Loops: Definition, Purpose, and Examples
A nested loop is a loop placed inside another loop, allowing you to process multidimensional data, compare sets of values, or iterate through layered structures.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › nested-loops-in-c-with-examples
Nested Loops in C - GeeksforGeeks
For a nested loop, the inner loop performs all of its iterations for each iteration of the outer loop. If the outer loop is running from i = 1 to 5 and the inner loop is running from j = 0 to 3.
Published   November 7, 2025
🌐
PCMAG
pcmag.com › home › encyclopedia › n
Definition of nested loop | PCMag
In programming, the positioning of a loop within a loop. The number of loops that can be nested may be limited by the programming language.
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit4-Iteration › topic-4-4-nested-loops.html
4.4. Nested For Loops — CSAwesome v1
A nested loop has one loop inside of another. These are typically used for working with two dimensions such as printing stars in rows and columns as shown below. When a loop is nested inside another loop, the inner loop runs many times inside the outer loop. In each iteration of the outer loop, ...
Find elsewhere
🌐
Codejumper
codejumper.com › downloads › htmls › lessons › en › Lesson14 › Lesson_14.html
Code Jumper Curriculum, Lesson 14: Nested Loops
Nested Loop: A loop within another loop, where the entire sequence of instructions/actions is repeated. After this lesson, students will understand the concept of a loop and how computer programs use nested loops.
🌐
EasyTechJunkie
easytechjunkie.com › what-is-a-nested-loop.htm
What is a Nested Loop? (with pictures)
May 16, 2024 - A nested loop is a logical structure used in computer programming to rapidly sort or insert large amounts of data. Nested loops...
🌐
O'Reilly
oreilly.com › library › view › computer-science-programming › 9781449356835 › fivedot4_for_loops_and_nested_loops.html
5.4 For Loops and Nested Loops - Computer Science Programming Basics in Ruby [Book]
April 24, 2013 - The range of values for num is defined by the construct 0..5 (see line 1), which represents all the integer values between 0 and 5 inclusive. Example 5-4. For loop ... A nested loop is a loop inside another loop.
Authors   Ophir FriederGideon Frieder
Published   2013
Pages   186
🌐
W3Schools
w3schools.com › c › c_for_loop_nested.php
C Nested Loops
It is also possible to place a loop inside another loop. This is called a nested loop.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_nested_loops.htm
Nested Loops in C
For example, nested loops, nested structures, nested conditional statements, etc. When a looping construct in C is employed inside the body of another loop, we call it a nested loop (or, loops within a loop).
🌐
Reddit
reddit.com › r/computerscience › explaining "nested loops" to someone without a computer's background
r/computerscience on Reddit: Explaining "Nested Loops" to Someone Without a Computer's Background
May 29, 2022 -

Does anyone know of a good example to explain Nested Loops to someone without a Computer's Background? I was thinking of an example where someone makes a checklist/decision tree for picking an ideal watermelon at a grocery store.

For example:

- Make sure the watermelon weighs more than 1 KG

- If YES, Make sure the watermelon is ripe

- If YES, Make sure the watermelon has no blemishes and dents

- If YES, Make sure the watermelon costs less than $10

- If YES, then buy.

Is this a good example of a Nested Loop - can someone please comment on this?

Thanks!

🌐
W3Schools
w3schools.com › python › gloss_python_for_nested.asp
Python Nested Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Practice Problems Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Training ... A nested loop is a loop inside a loop.
🌐
Vaia
vaia.com › nested loops in c
Nested Loops in C: Definition & Example | Vaia
Performance Consideration: Nested ... Loop Control Variable, and Exit Condition. ... A Nested Loop is a loop inside another loop, where the inner loop completes all its iterations before the outer loop proceeds....
🌐
Fiveable
fiveable.me › all key terms › ap computer science a › nested loops
Nested loops: AP Computer Science A Study Guide | Fiveable
Nested loops refer to the concept of using one loop inside another loop. This allows for iteration through multiple levels or dimensions of data. Nested loops cheat sheet for homeworkvisual study aid · Loop control variable: A loop control variable is a variable that keeps track of the current ...
🌐
Eokultv
whatis.eokultv.com › anasayfa › computer science & technology › what are nested loops in computer science? a high school introduction
🚀 Master Nested Loops: The Ultimate Guide
April 4, 2026 - In computer science, a nested loop is a loop placed inside another loop. The inner loop executes completely for each iteration of the outer loop.
🌐
Medium
medium.com › @Dev_Frank › nested-loop-in-c-for-loop-8e095615ae7c
NESTED LOOP IN C (for loop). Mastering Nested Loops for Efficient C… | by Dev Frank | Medium
January 21, 2024 - NESTED LOOP IN C (for loop) In C programming, a nested loop is a loop inside another loop. This allows you to iterate over a set of elements in a more complex pattern. The inner loop runs multiple …