+ 7

Can one stop an infinite loop ?

30th Sep 2017, 10:07 AM
ayush sharma
ayush sharma - avatar
9 Respostas
+ 26
Only Superman can stop it. That's why programmers avoid infinite loops with the break statement or with the right conditions.
30th Sep 2017, 10:25 AM
Igor Makarsky
Igor Makarsky - avatar
+ 2
If the loop is inside a function, you can put a condition inside it and use return to get out of the function.
2nd Oct 2017, 10:34 AM
Lucas Barros Lima
Lucas Barros Lima - avatar
+ 2
you can correct the code by using a condition that is actually possible. if not it will continue running
2nd Oct 2017, 1:49 PM
Hanis Hapsa
Hanis Hapsa - avatar
+ 1
Yes, break
30th Sep 2017, 11:03 AM
Clifford Winburn
+ 1
ctrl c
30th Sep 2017, 11:28 AM
Oma Falk
Oma Falk - avatar
+ 1
In general, There are ways to stop an infinite loop 1.using a break statement - which is not a good way to terminate the loop (unless you free your resources) 2.mention/use a loop condition that causes the loop to terminate gracefully. 3.define a timeout in your application, once it occurs write a handler that would free resources and use a break. 3.a Simulate a timeout using interrupts/timers if it is an embedded application. 3.b if it is a linux system application, send a signal like SIGUSR1 handle it, free resources and terminate the loop these are only few ways.There may be more depending on the application and coding environment in practice.
1st Oct 2017, 6:31 AM
balachandar
balachandar - avatar
+ 1
break;
2nd Oct 2017, 5:23 AM
Kumaresan L
Kumaresan L - avatar
0
Just press the buttons ctrl+c
1st Oct 2017, 5:51 PM
Sneha V
Sneha V - avatar
0
Hate infinite loops like Medusa! They are disastrous sometimes. When making loops cross-check to be sure it is not infinite before moving on. During my early Java2D days, I mistakenly made scan infinite loop. So terrible it took me 30 minutes! To shut down my windows 7 PC
2nd Oct 2017, 9:39 AM
Ore
Ore - avatar