+ 3
I can't understand this code
i = 0 while True: i = i +1 if i == 2: print("Skipping 2") continue if i == 5: print("Breaking") break print(i) print("Finished")
3 Answers
+ 7
i = 0
#initial value
while True:
i = i +1
if i == 2:
print("Skipping 2")
continue
if i == 5:
print("Breaking")
break
print(i)
print("Finished")
when codition of when loop is true than
i=i+1
i=0+1=1
i=1+1=2=> if condition true so output "skipping 2" then because of continue statment loop is again start by value 2
i=2+1=3
i=3+1=4 then
i=4+1=5 if statement evaluted and print breaking
then break the loop
and at last print finished
so the output become :-
1
skipping 2
3
4
breaking
finish
+ 7
@Pegasus fixed itđđ
+ 6
Your explanation is awesome @GAWEN.
Just one problem: Python's comments are either:
#this
or
'''
this
'''
Not //. This is floor division