Posts: 6,419
Threads: 74
Joined: Mar 2002
see?
more than 14,000 gotos on Linux source
The issue is not: "goto is bad", but "people don't know how to use goto properly".
Mind you.
Posts: 134
Threads: 13
Joined: Jun 2003
GOTO is evil???? Why?
Other ideas:
Make an exit variable:
If exit is 0 then the loop goes, but when it is 1, the loop exits.
If You need to exit in the middle of the loop, place an IF exit==0 before the unwanted code (Of course, dont forget to put that between the {})
If You have a FOR cycle, simply increase the counter to it's maximum, and the loop will exit.
Anyway, I sometimes use GOTO, but else I use these.
Posts: 1,407
Threads: 117
Joined: Dec 2002
To exit a loop you can use whatever you want:
Code:
#define Go_Away_off_this_darn_loop exit
in C++ defines are evil so you should do something smarter..
Antoni
Posts: 6,419
Threads: 74
Joined: Mar 2002
Quote:GOTO is evil???? Why?
Other ideas:
Make an exit variable:
If exit is 0 then the loop goes, but when it is 1, the loop exits.
If You need to exit in the middle of the loop, place an IF exit==0 before the unwanted code (Of course, dont forget to put that between the {})
If You have a FOR cycle, simply increase the counter to it's maximum, and the loop will exit.
Anyway, I sometimes use GOTO, but else I use these.
yeah, there are workarounds. But goto is faster and straightforward. You can exit 27 nested loops/ifs/whends/cases/whatevers in a while. No need to do 27 checks.
Posts: 691
Threads: 5
Joined: Apr 2002
The MINIX code I am working with has some funky goto code like this:
Code:
<In the kernel>
rp->p_reg.pc = __sigreturn;
rp->p_reg.npc = rp->p_reg.pc + 4;
<In the library>
__sigreturn:
ld [%sp + 96], %o0
...
It allows jumps to arbitary points in code (even to other functions) without causing a stack save, the __sigreturn function can then read info straight from the stack.
esus saves.... Passes to Moses, shoots, he scores!
Posts: 6,419
Threads: 74
Joined: Mar 2002
LooseCaboose is a genius. Listen to him. I am just to back him. Gotos are for really good, experienced programmers. They save time if used correctly. Processors are simple: they perform arithmetic operations, do memory accesses, and jump. Goto = jump. What's wrong?