+ 1

Infinite Loop. .. Please help!

Hello, please check the code. I've tried use "while d<=len(decr)+1" in line 18, but it didn't work - the cycle didn't stop! I resolved the problem using "try - except" construction, but didn't get what was the problem! Please, help! Thanks!! https://code.sololearn.com/c03esaSeFv0C/?ref=app

24th Mar 2018, 12:18 PM
Михаил Корощенко
Михаил Корощенко - avatar
9 Answers
+ 2
Take a look at the code again. Replacing while True by while d < len(decr) - 1 will solve your issues... while d < len(decr) - 1 makes you loop through decr
24th Mar 2018, 1:06 PM
cyk
cyk - avatar
+ 4
Since you're modifying the string you are looping on, it is usually safer to start at the end and process to the beginning. That way the stuff you haven't touched remains fixed, while the stuff you have processed grows or shrinks.
24th Mar 2018, 12:59 PM
John Wells
John Wells - avatar
+ 2
You need a break statement somewhere... The statement "while true" will make the loop run infintely unless there is break
24th Mar 2018, 12:44 PM
cyk
cyk - avatar
+ 2
When you are done, please let me know if it solves the issue :)
24th Mar 2018, 12:46 PM
cyk
cyk - avatar
+ 2
All right. Take a look at this code https://code.sololearn.com/cedI6NBZvk7I/?ref=app
24th Mar 2018, 12:56 PM
cyk
cyk - avatar
+ 2
Use http://pythontutor.com/ to visualise your code - if it ^stalls^ due to an infinite loop, it will help you to see where it is.
24th Nov 2018, 10:02 PM
Jonathan Shiell
+ 1
Yembik, yes I've used "try - except" instead break. But before I tried "while d<=len(decr) +1" - so when d is becomes more then length of the list it have to stop - but it don't. I tried to return d - it is increasing infinitly. So, do you know where can be the problem?
24th Mar 2018, 12:49 PM
Михаил Корощенко
Михаил Корощенко - avatar
+ 1
Your questions are absolutely not stupid! We were all beginners one day. And I was very happy to help :)
24th Mar 2018, 2:25 PM
cyk
cyk - avatar
0
Thanks a lot! I started learning programming just 3 days ago, so I'm sorry if my questions are stupid
24th Mar 2018, 2:21 PM
Михаил Корощенко
Михаил Корощенко - avatar