0
loops
what does it mean when your code outputs " Time limit exceeded "
7 ответов
+ 3
use break statement instead of any one continue statement..
since no break is used it enters into infinite loop
i = 0
while True:
i = i +1
if i == 2:
print("Skipping 2")
continue # use break here or
if i == 5:
print("Breaking")
continue # use break here
print(i)
print("Finished")
in general while statement has to Fail in order to exit the loop,.over here it never happens.
eg : fix an limit and change while loop in accordance, like..
while not i == 10:
on this case,.. when i iterates from 0-9,
i will not be equal to 10 and at the same time we have issued 'not' in front of comparison statement. this means,..
while not False: # which is true
when i becomes 10
while not True: # which is False, loop exit's
0
با
0
don't get you
0
what did u try exactly..
post ur code plz
0
i = 0
while True:
i = i +1
if i == 2:
print("Skipping 2")
continue
if i == 5:
print("Breaking")
continue
print(i)
print("Finished")
0
thanks
- 1
Paste your code with that mistake here