So, I'm learning Python through a series of videos on YT and this time, while loops are being covered. The exemple code is thus:
given_list2=[5,4,4,3,1,-2,-3,-5]
total3=0
i=0
while True:
total3+=given_list2[i]
i+=1
if given_list2[i]<=0:
break
print(total3)
Running the script, I get 17 as a result. Then, experimenting with the code, I exchanged True
for False
as thus:
given_list2=[5,4,4,3,1,-2,-3,-5]
total3=0
i=0
while False:
total3+=given_list2[i]
i+=1
if given_list2[i]<=0:
break
print(total3)
And it gives me 0 as a result. I'm trying to understand why that's the case. Like, what is it being considered True
that keeps running the code, and what is being considered False
that it fails to even initialize the code?