How to use Switch from within a loop?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Saturn
Posts: 418
Joined: Mon Sep 25, 2006 5:58 pm

Post by Saturn »

Pörzi wrote: Imo there are two reasons why one should not use goto:

1) It is generally not regarded as a good way to program.
2) The code will not be easy to read if you use is a lot.
Argument 1 is circular reasoning and thus logically invalid. Unless you are talking about the social consequences. ("Eww, he's using goto, I'm not gonna talk to him anymore.")
Argument 2 is valid for just about anything. Templates anyone?

When you have three nested loops (and yes, sometimes this is valid. ;)) and want to break early from within the inner most loop, then goto is the most elegant solution. There are other ways, like breaking the routine further down into multiple functions or using done-flags, but they are not always applicable or make the code less readable.

Goto is also often used for error handling, see Blender source for an example.
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Pah, goto. Real hackers use setjmp()/longjmp() to inflict pain on maintainers. ;)
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply