Python – How to use a double while loop in python

python

Does a python double while loop work differently than a java double loop?
When I run this code:

i = 0
j = 1
while i < 10:
    while j < 11:
        print i, j
        j+=1
    i+=1

I get the following output:

0 1
0 2
0 3
0 4
0 5
0 6
0 7
0 8
0 9
0 10

I want it to keep looping to print 1 0, 1 1, 1 2, … 2 0, 2 1, 2 3… etc. Why does it stop after only one iteration?

Best Solution

You probably want to move the j "initialization" inside the first loop.

i = 0
while i < 10:
    j = 1
    while j < 11:
        print i, j
        j+=1
    i+=1

In your code, as soon as j gets to 11, then the inner loop stops executing (with the print statement). In my code, I reset j each time i changes so the inner loop will execute again.