If you're frequently iterating over a Cartesian product like in your example, you might want to investigate Python 2.6's itertools.product -- or write your own if you're in an earlier Python.

from itertools import product
for y, x in product(range(3), repeat=2):
  do_something()
  for y1, x1 in product(range(3), repeat=2):
    do_something_else()
Answer from alicederyn on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-nested-loops
Python Nested Loops - GeeksforGeeks
Inner loop runs from 1 to 10. Each inner loop iteration multiplies the outer loop value with the inner loop value. Example 3: Printing using different inner and outer nested loops
Published ย  4 days ago
๐ŸŒ
Real Python
realpython.com โ€บ nested-loops-python
Nested Loops in Python โ€“ Real Python
May 21, 2025 - Browse Topics Guided Learning Paths ... web-scraping ... Nested loops in Python allow you to place one loop inside another, enabling you to perform repeated actions over multiple sequences....
Discussions

[Python] Can someone please explain to me how nested for loops work using this example. I don't understand how it works
What does this do? for j in range(i,userInput): print('*', end=' ') If you don't know, try it. Assign values to i and userInput manually and see if you can figure it out. More on reddit.com
๐ŸŒ r/learnprogramming
15
1
March 11, 2025
In python is there an easier way to write 6 nested for loops? - Stack Overflow
This problem has been getting at me for a while now. Is there an easier way to write nested for loops in python? For example if my code went something like this: for y in range(3): for x in ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python Code for nested loops
Does anyone know how to print the following pattern using nested loops? 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 More on discuss.python.org
๐ŸŒ discuss.python.org
0
0
August 31, 2022
How to continue in nested loops in Python - Stack Overflow
How can you continue the parent loop of say two nested loops in Python? for a in b: for c in d: for e in f: if somecondition: More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_nested.asp
Python Nested Loops
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... A nested loop is a loop inside a loop.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_nested_loops.htm
Python - Nested Loops
In Python, when you write one or more loops within a loop statement that is known as a nested loop. The main loop is considered as outer loop and loop(s) inside the outer loop are known as inner loops.
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ nested loops in python
Nested Loops in Python
September 2, 2021 - Nested loops are typically used for working with multidimensional data structures, such as printing two-dimensional arrays, iterating a list that contains a nested list. A nested loop is a part of a control flow statement that helps you to ...
๐ŸŒ
Softuni
python-book.softuni.org โ€บ chapter-06-nested-loops.html
Chapter 6.1. Nested Loops - Programming Basics with Python
Test your solution here: ... a rectangle made out of N x N asterisks. ... A nested loop is a construction where the body of one loop (the outer one) stays inside another loop (the inner one)....
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ python tutorial โ€บ python nested loops
Python Nested Loops | Complete Guide To Nested Loops in Python
May 10, 2024 - It would be good to briefly touch base upon Nested Loops in general before proceeding with Python specifically. If a loop exists inside the body of another loop, it is termed as Nested Loop. This means that we want to execute the inner loop ...
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @danielbuilescu โ€บ master-python-loops-for-while-and-nested-loops-bf93ac4cd3a0
Master Python Loops: For, While, and Nested Loops | by Builescu Daniel | Medium
June 14, 2023 - Master Python Loops: For, While, and Nested Loops Welcome, fellow developers! If youโ€™re on a journey to master Python or just want to brush up your skills, youโ€™ve come to the right place. In this โ€ฆ
๐ŸŒ
OpenStax
openstax.org โ€บ books โ€บ introduction-python-programming โ€บ pages โ€บ 5-3-nested-loops
5.3 Nested loops - Introduction to Python Programming | OpenStax
March 13, 2024 - A nested loop has one or more loops within the body of another loop. The two loops are referred to as outer loop and inner loop. The outer loop controls the number of the inner loop's full execution.
๐ŸŒ
Programiz PRO
programiz.pro โ€บ resources โ€บ python-nested-loop
Understanding Nested Loops in Python with Logic Building
A nested loop is a loop inside another loop. The outer loop determines how many times the inner loop will execute. This is particularly useful for tasks involving multi-row or multi-column structures, such as grids or patterns.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ python โ€บ nested-loops
Nested Loops in Python: Uses, Working, Syntax, Examples
November 5, 2025 - Understand how Python nested loops work, their syntax, and practical examples to enhance your programming skills and solve complex problems efficiently.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Python Code for nested loops - Python Help - Discussions on Python.org
August 31, 2022 - Does anyone know how to print the following pattern using nested loops? 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ python programming for beginners โ€“ free python tutorials โ€บ python loops โ€“ for, while, nested loops with examples
Python Loops - For, While, Nested Loops With Examples
April 1, 2025 - However, a third loop[nested loop] can be generated by nesting two or more of these loops. Looping statements in python are used to execute a block of statements or code repeatedly for several times as specified by the user.
๐ŸŒ
Codingem
codingem.com โ€บ home โ€บ nested loops in python: a complete guide
Nested Loops in Python: A Complete Guide - codingem.com
January 25, 2024 - A nested loop in Python is a loop inside a loop. This guide teaches you how to work with nested loops in Python with illustrative examples.
๐ŸŒ
Geek Python
geekpython.in โ€บ nested-for-loops-in-python
Understanding Nested for Loops in Python - How Does it Work
March 1, 2024 - In Python, nested for loops are loops that have one or more for loops within them.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Nested loops in Python are easy
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.