0

loops

what does it mean when your code outputs " Time limit exceeded "

1st Sep 2016, 8:44 PM
Kuzzz
Kuzzz - avatar
7 odpowiedzi
+ 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
2nd Sep 2016, 2:28 PM
arvindh
arvindh - avatar
0
با
1st Sep 2016, 8:55 PM
النورعبدالشافع ابكر
0
don't get you
1st Sep 2016, 9:24 PM
Kuzzz
Kuzzz - avatar
0
what did u try exactly.. post ur code plz
2nd Sep 2016, 3:46 AM
arvindh
arvindh - avatar
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")
2nd Sep 2016, 2:25 PM
Kuzzz
Kuzzz - avatar
0
thanks
2nd Sep 2016, 2:33 PM
Kuzzz
Kuzzz - avatar
- 1
Paste your code with that mistake here
2nd Sep 2016, 4:44 AM
Leshark
Leshark - avatar