Not sure what your problem is, maybe you want to put that x=0 right before the inner loop ?

Your whole code doesn't look remotely like Python code ... loops like that are better done like this:

for b in range(0,11):
    print 'here is the outer loop',b
    for x in range(0, 16):
        #k=p[x]
        print 'here is the inner loop',x
Answer from Jochen Ritzel on Stack Overflow
🌐
Kansas State University
textbooks.cs.ksu.edu › intro-python › 05-loops › 08-nested-while
Nested While Loops :: Introduction to Python
June 27, 2024 - When we run this code, each time we execute the steps inside of the outer while loop, we’ll have to completely go through the inner while loop as well. It can be very complex to keep track of everything, but with a bit of practice we’ll learn some strategies for mentally working through loops. Before continuing, take a look at that program’s code and see if you can determine what it will print! To really understand how a set of nested loops work, let’s go through a code tracing example using Python Tutor.
Discussions

Nested while loops
Trying to find specific resources for specific combinations of bits of syntax will be difficult. After all, there's nothing special about the way a nested while loop works versus a not-nested one. Any resource that talks about loops will cover while loops. Without specific questions or specific pieces of code the best one could do is give generic help: use multiple resources, do both practice exercises and theory, and every line of code you write yourself is worth a thousand you read in a book. More on reddit.com
🌐 r/learnpython
5
2
February 25, 2025
Nested While Loops
The following program is supposed to output numbered rows and columns (as in 1A, 1B, 1C, etc.) based on user input. If user enters 1 3, the output should be (1A 1B 1C). If the user enters 5C, the output should be (1A 1B 1C 2A 2B 2C 3A 3B 3C 4A 4B 4C 5A 5B 5C), etc. More on discuss.python.org
🌐 discuss.python.org
10
0
October 20, 2021
While/For/Nested Loops
Please format your code correctly so that it's legible. Whitespace matters in Python, so formatting matters when trying to help you out. There aren't any nested loops happening here. Can you correct your code formatting and try adding comments to explain what is happening line by line. More on reddit.com
🌐 r/learnpython
9
0
March 21, 2023
Is it bad to use a lot of nested while loops?
You could try splitting things out into functions to avoid nesting too deep in loops. More on reddit.com
🌐 r/learnpython
20
91
November 13, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-nested-loops
Python Nested Loops - GeeksforGeeks
For example, a while loop inside a for loop, or a for loop inside another for loop. ... Outer_loop Expression: Inner_loop Expression: Statement inside inner_loop Statement inside Outer_loop ...
Published   March 13, 2026
🌐
TutorialKart
tutorialkart.com › python › python-while-loop › python-nested-while-loop
Python Nested While Loop - Examples
November 30, 2020 - Like three while loops one inside another. ... i = 1 while i <= 4 : j = 0 while j <= 3 : k = 0 while k <= 5 : print(i*j*k, end=" ") k += 1 print() j += 1 print() i += 1 ... 0 0 0 0 0 0 0 1 2 3 4 5 0 2 4 6 8 10 0 3 6 9 12 15 0 0 0 0 0 0 0 2 4 6 8 10 0 4 8 12 16 20 0 6 12 18 24 30 0 0 0 0 0 0 0 3 6 9 12 15 0 6 12 18 24 30 0 9 18 27 36 45 0 0 0 0 0 0 0 4 8 12 16 20 0 8 16 24 32 40 0 12 24 36 48 60 · In this Python Tutorial, we learned how to write Nested While Loops in Python.
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 5-3-nested-loops
5.3 Nested loops - Introduction to Python Programming | OpenStax
March 13, 2024 - The outer loop can be implemented using a for loop iterating over the provided list, and the inner loop iterates over all even numbers less than a given number from the list using a while loop. numbers = [12, 5, 3] i = 0 for n in numbers: while ...
🌐
EyeHunts
tutorial.eyehunts.com › home › nested while loop in python | example code
Nested while loop in Python | Example code
June 21, 2023 - When a while loop is used inside another while loop then it is called nested while loop in Python. Python allows using one loop inside...
🌐
PYnative
pynative.com › home › python › nested loops in python
Nested Loops in Python
September 2, 2021 - print('Show Perfect number fom 1 to 100') n = 2 # outer while loop while n <= 100: x_sum = 0 # inner for loop for i in range(1, n): if n % i == 0: x_sum += i if x_sum == n: print('Perfect number:', n) n += 1 Code language: Python (python) Run · Nested loops are handy when you have nested arrays or lists that need to be looped through the same function.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › nested while loops
r/learnpython on Reddit: Nested while loops
February 25, 2025 -

Could someone provide me with a link for nested while loops so I can understand them better? I have read about them and I also practiced them, however I find them hard to understand how they are supposed to function.

🌐
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.
🌐
Real Python
realpython.com › lessons › nested-while-loops
Nested While Loops (Video) – Real Python
00:00 So while we are looking at this example, there’s actually one more thing we can talk about, and that’s the idea of having these nested conditional statements. 00:08 So, we have our while loop out here and inside of it, we have nested another conditional statement, an if statement.
Published   March 1, 2019
🌐
ScholarHat
scholarhat.com › home
Loops in Python - For, While loop (With Examples)
September 10, 2025 - A nested loop in Python means using one loop inside another loop. It is commonly used when you need to repeat actions in a multi-level structure, like printing patterns or working with multi-dimensional lists (like 2D arrays). for iterating_var ...
🌐
Tutorialspoint
tutorialspoint.com › python › python_nested_loops.htm
Python - Nested Loops
The following program uses a nested ... jan tue feb sun feb mon feb tue mar sun mar mon mar tue Good bye! The while loop having one or more inner while loops are nested while loop....
🌐
Scientech Easy
scientecheasy.com › home › blog › nested loops in python
Nested Loops in Python - Scientech Easy
January 25, 2026 - Like nested for loop, when we place a while loop inside another while loop body, then we call it as a nested while loop statement. The general syntax for a nested while loop statement in Python programming language is as below:
🌐
BigBinary Academy
courses.bigbinaryacademy.com › learn-python › while-loop › nested-while-loops
Nested While loops - Learn Python | BigBinary Academy
We can also place a while loop within another while loop. This is also known as nesting a while loop. The program below multiplies every number of `numbers_list_1` with `numbers_list_2` using nested while loops.
🌐
Python.org
discuss.python.org › python help
Nested While Loops - Python Help - Discussions on Python.org
October 20, 2021 - The following program is supposed to output numbered rows and columns (as in 1A, 1B, 1C, etc.) based on user input. If user enters 1 3, the output should be (1A 1B 1C). If the user enters 5C, the output should be (1A 1B …
🌐
BeginnersBook
beginnersbook.com › 2018 › 01 › python-while-loop
Python While Loop
March 14, 2019 - When a while loop is present inside another while loop then it is called nested while loop.
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
... Note: It is suggested not to use this type of loop as it is a never-ending infinite loop where the condition is always true and we have to forcefully terminate the program (or loop execution). A nested loop is a loop inside another loop.
Published   June 11, 2026
🌐
Medium
medium.com › @friedman.sydneyl › mastering-nested-while-loops-in-python-a-step-by-step-guide-9a0b30b01abd
Mastering Nested While Loops in Python: A Step-by-Step Guide | by Sydney Friedman | Medium
September 10, 2024 - Iterating through elements: We need to compare each number with every other number in the array. Loops are perfect for that. Checking combinations: We’re looking for pairs of numbers. That means using nested loops — one loop to pick the first number and another to check the rest.
🌐
Real Python
realpython.com › nested-loops-python
Nested Loops in Python – Real Python
February 22, 2025 - Test your understanding of nested loops in Python! Loops are fundamental building blocks in programming, allowing you to iterate through actions efficiently. In Python, there are two primary types of loops: the for loop and the while loop.
🌐
GeeksforGeeks
geeksforgeeks.org › loops-in-python
Loops in Python - For, While and Nested Loops - GeeksforGeeks
Python programming language allows to use one loop inside another loop which is called nested loop. Following section shows few examples to illustrate the concept. for iterator_var in sequence: for iterator_var in sequence: statements(s) statements(s) The syntax for a nested while loop statement in the Python programming language is as follows:
Published   March 8, 2025