On Mon, 14 Apr 2003 22:15:45 -0400 (PYT) Raúl Gutiérrez Segalés <rau@campoalto.edu.py> wrote:
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;
case 'x': goto end; break; } }
end:
Is this something not very advisable to do? Well at least that is what an author suggested.. in my short experience I can firmly say that it doesnt look so clean on my code.. I've read all the other responses. In my 20 years of using the C language, I have never had the occasion to use goto in my own code. HOWEVER, there are cases when you might be very deep in a nesting situation where it may be appropriate. Derek's example, while(looping && condition)
works well, but adds another test in the loop. You might have something like: case 'x': /* falsify the condition */ continue; In a recent porting project of complex code involving multi-level locking there was a case where a goto was used such that all code would exit through a common unlocking point. My criteria has always been to keep code an simple and straighforward as possible. If an occasional goto is needed, then by all means use it. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9