Sorry for the noob question, but someone pls explain me the inner workings of this nested for loop.
v,w = 2,4
for v in range(v):
for w in range(w):
print('v=',v,'w=',w)
If I run it like this, the output will be as follows:
v= 0 w= 0
v= 0 w= 1
v= 0 w= 2
v= 0 w= 3
v= 1 w= 0
v= 1 w= 1
v= 1 w= 2
I figured it stops 'prematurely' (the last output v= 1 w= 3 is missing) cause the last value assigned to the 'w' variable was 3 before the last loop ran.
If I run it like this, it works, but doesn't look Pythonic to say the least.
v,w = 2,4
for v in range(v):
for w in range(w):
print('v=',v,'w=',w)
w = 4
Could some please explain how this problem is best addressed?
wends at 3 after first iteration of outer loop.for v_ in range(v): for w_ in range(w)