On Tue, 2003-04-15 at 04:15, Raúl Gutiérrez Segalés wrote:
Hi,
Today while I wwas coding I noted that I almost always use goto in this constructs:
while(condition) { switch(some_var) { case 'y': do_something(); break;
A break is a goto too, in a sense.
case 'x': goto end;
I don't think a goto used in this way is so terrible. It's still fairly linear code. The big problem with "goto" is that if it's misused it can lead to code that is extremely difficult to follow. For example goto:s jumping out of or in to procedures. In this particular case I don't see "goto end" any more difficult to follow than "break".
break;
but if this is ever reached you should file a bug report with the compiler people :)
} }
end:
Is this something not very advisable to do? Well at least that is what an author suggested..
Some people think "goto" should be completely banned from programming (would this include JMP in assembly I wonder :) but I don't think so. It should be used with extreme caution though. Take it from someone who has had to work with maintenance of very old, very crufty and very huge source files. If used properly and carefully, it can lead to code that is even easier to read than the alternative. But if used improperly you will want to kill yourself rather than have to read the code 15 years later.