0

How does this code work? (break down the code)

(from code challenge) https://code.sololearn.com/chFru359X9d3/?ref=app

5th Feb 2021, 6:04 PM
Noobgram
Noobgram - avatar
4 Antworten
+ 1
Python is not C While loops don't have a scope of their own The python scopes are Built-in Global Enclosed (functions) Local (nested functions)
6th Feb 2021, 1:33 PM
Angelo
Angelo - avatar
+ 2
It enters the infinite loop (while True) First iteration: for n in 0...9 it does nothing At the end of the for loop n is 9 The break statement breaks the while loop print(n) prints n(=9)
5th Feb 2021, 6:23 PM
Angelo
Angelo - avatar
0
But n wasn't declared outside while loop's scope, in fact it should belong to for loop's scope. And when the code block ends, shouldn't the variable be garbage collected?
6th Feb 2021, 7:29 AM
Noobgram
Noobgram - avatar
0
Thanks, that's what I was looking for
7th Feb 2021, 8:21 AM
Noobgram
Noobgram - avatar