![]() |
Breaking out of nested infinite while loops.
Can anyone tell me how to do as the title says? I'm told that using goto is a no no. Here is some sample code that i can't seem to be able to figure out. I'm a novice by the way ;)
Code:
#include<stdio.h> |
Re: Breaking out of nested infinite while loops.
The "break" keyword will break you out of the loop:
Code:
while(1){ |
Re: Breaking out of nested infinite while loops.
Hi. I know about break. How do you break from a multiple loop. Look at my example again. :)
|
Re: Breaking out of nested infinite while loops.
You'll have to use multiple breaks.
|
Re: Breaking out of nested infinite while loops.
My way :)
Code:
#include<stdio.h> |
Re: Breaking out of nested infinite while loops.
The correct answer depends very much on what you are trying to do. Nesting three infinite loops isn't a practical design for anything I've come across. Let us know what problem you're trying to solve and we'll see if we can come up with a better solution.
On the other hand if this is just for academic interest, yeah, just use a goto, whatever works. Makes no difference. |
| All times are GMT +5.5. The time now is 04:15. |