Whats the forever loop code in Python? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1
31st Dec 2016, 1:02 AM
Tyrone
Tyrone - avatar
6 Answers
+ 2
Yes something like that. You should put it in the begining of part of code, that must be executed infinitely. If you have function definition in your code - they probably should stay out of the loop, or they'll be redefined on each iteration.
31st Dec 2016, 3:09 AM
Dmitry Zolnikov
Dmitry Zolnikov - avatar
+ 1
I believe there is a small misprint in previous example: it must have 'while' instead of 'if'. To put it simply: infinite or forever loop is a loop, where condition always stay True. All code in this type of loop will be executed over and over again, unless it will be broken manually or some error will be raised.
31st Dec 2016, 2:53 AM
Dmitry Zolnikov
Dmitry Zolnikov - avatar
0
if True: print(1) that's an example
31st Dec 2016, 1:37 AM
Valentino Ugbala
Valentino Ugbala - avatar
0
ok. thats a good one.I'm guessing that only goes for whatever the number I put between the parentheses right?
31st Dec 2016, 2:31 AM
Tyrone
Tyrone - avatar
0
ok so do I put it at the beginning of all my code?
31st Dec 2016, 2:58 AM
Tyrone
Tyrone - avatar
0
it goes for whatever code you put under the if block
2nd Jan 2017, 1:42 AM
Valentino Ugbala
Valentino Ugbala - avatar