+ 7
Can one stop an infinite loop ?
9 Réponses
+ 26
Only Superman can stop it. That's why programmers avoid infinite loops with the break statement or with the right conditions.
+ 2
If the loop is inside a function, you can put a condition inside it and use return to get out of the function.
+ 2
you can correct the code by using a condition that is actually possible. if not it will continue running
+ 1
Yes, break
+ 1
ctrl c
+ 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.
+ 1
break;
0
Just press the buttons ctrl+c
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