"TheEndless" wrote:
"EnTerr" wrote:
Continue is easy to emulate with Goto:
[velociraptor cutout, http://xkcd.com/292/]
Of course there are options, but if you read the original post that started the conversation, the whole reason "continue" was brought up was to avoid having to use a ton of nested if/elseif/endif blocks.
Continue typically it is replaced with a single
if not ...
end if. Off hand i cannot think of example where "a ton of nested if/elseif/endif blocks" will be needed for that, can you?
Regarding the "here be dragons" part, hoped not having to explain but okay: during the process of learning, first we have to learn a simplified version of truth - for example first they tell you in school "you cannot subtract bigger number from a smaller one" - and a year later they say "meet the negative numbers". Or "5 is not divisible on 3" before meeting fractions, "you cannot take square root from negative number" before imaginary numbers etc. In the same way "thou shalt not use GOTO" when learning to program. First you need some training wheels - true, they prevent you from making sharp turns - but without them might not have even learned how to ride the programming bike. Later they come off.
Here is
list of limited cases where GOTO is beneficial. Here is
example of multi-level exit that
break can't muster. Do i use GOTOs - i can't remember when was the last time i did - but it is also rare for me to use break/continue either. In case have not thought about it,
break/continue/return are just GOTOs in disguise, addressing the most beneficial cases/needs. Even Dijkstra (who made the case against GOTO) - for all his
arrogance - later cautioned "Please don't fall into the trap of believing that I am terribly dogmatical about [the go to statement]. I have the uncomfortable feeling that others are making a religion out of it, as if the conceptual problems of programming could be solved by a single trick, by a simple form of coding discipline!" There is no silver bullet in programming.
PS. Even
switch/case can be used to make a bloody mess, exhibit
Duff's Device - first time i saw it, i was like, "that's not even syntactically correct, interleaving switch and while loop" - but it is in C, compiles and works - and can give you hangover just from trying to understand it. If it helps,
switch(expr) in C is just an arithmetic
goto expr where
case X are the "X:" labels for that goto.
PPS. Never mind GOTO - apparently in PHP one can do effectively the mythical COMEFROM statement:
switch (true) {
case $x: ...
case ($y > 10): ...
case (rand(1,10) < 3): ...
}