I did a lot of calculator programming the past few years.
In calculator programming, you can make a part of a command skip to another loop, and it would look something like this
Lbl A
Disp "Cheese"
If X=5; Goto B
Goto A
Lbl B
Disp "Queso?"
Goto B
Well, that bit of code passed the "verify" test. Nice work. You know, teaching arduino programmers goto commands is one of the 796.5 deadly sins. I believe it is number 652.
/I've probably just committed some cardinal sin by introducing the Arduino masses to the goto statement...
Oh it's been discussed before, trust me. Usually with a zillion repeated posting (from mostly low count posters) saying never, never, ever, ever use it, it's evil, evil.
Then once in a blue moon some old sage will quietly explain that it is not evil if used as designed for special situations (error recovery routines are often stated). Of course such reason is usually lost in the extremely low S/N ratio of such threads.
Lets put it this way, if it was pure evil why would the K&R gods designed it into the C language? Certainly as used in the classic Basic language it breaks the rules of structured programming. But dammit, when one really needs a 10 pound sledge hammer, it's nice to know there is one close at hand in the tool box.
Then once in a blue moon some old sage will quietly explain that it is not evil if used as designed for special situations (error recovery routines are often stated).
An old sage that is using goto instead of exception handling for error recovery must be very old indeed.
Alas, exception handling isn't supported in avr gcc, but I doubt that any good would come from Arduino users trying to use goto to recover from errors.
As K&R say in The C Programming Language:
“C provides the infinitely–abusable goto statement. Formally, the goto is never necessary.”
I think they only put the construct in the language to provide a talking point for bored old sages
I think they only put the construct in the language to provide a talking point for bored old sages
Could be, I haven't used it as yet. C is still pretty new to me and anyway hardware is where my heart and experience lies rather then software. However I'm always a little suspicious with people using near religious arguments (have faith, goto is evil) when discussing a technical point.
Then again I'm probably just as bad telling new comers never to use LEDs without resistors, or powering servos directly from a Arduino is evil, evil I say.
I would say programmers in general are "weird people", Buzzsushi. And the closer we get to the hardware, the weirder we become (my closest hardware experience was doing hand-assembly of 6502 assembler in the monitor program on the Apple IIe - that was fun; I hope to in the future replicate that experience when I get my Altair refurbished and working - should be fun to toggle in test code!).
For instance, take Ada Lovelace; she is considered the world's first programmer (and has a programming language named for her), she was a babe (for her time - hell, even today), and sadly died young:
Her hardware: Babbage's Analytical Engine
Her software: Code to compute Bernoulli numbers
She wrote the software "blind" - that is, she had no hardware to test it on, only what she knew of Babbage's machine, her notes, her notes on the algorithm, etc.
This was in 1843; it wasn't recognized exactly what she had accomplished until 1953 - over a century later after her death in 1852.
It's a pity that more women don't know about this amazing lady, and as a consequence go into the more technical arts. Of course, there's always the founder of AdaFruit:
So there's hope...
[edit]Kinda left something off - what I was meaning to mention about Ada Lovelace, as related to "weird programmers":
Victorian-era Britain
Female
Skilled in mathematics (!)
Programmed a computer (!!)
That didn't exist (!!!)
For a mid-19th century woman, this is extraordinary; this is way before women's lib, and right in the middle of the beginning of the women's suffrage movement. Her actions would've been seen as a curiousity at best, scandalous at worst; the fact that her work wasn't recognized for what it was until a century after her death speaks volumes.
If that doesn't scream "weird programmer", I don't know what does (though I sincerely doubt she saw herself that way)...[/edit]
An old sage that is using goto instead of exception handling for error recovery must be very old indeed.
Alas, exception handling isn't supported in avr gcc, but I doubt that any good would come from Arduino users trying to use goto to recover from errors.
As K&R say in The C Programming Language:
“C provides the infinitely–abusable goto statement. Formally, the goto is never necessary.”
I think they only put the construct in the language to provide a talking point for bored old sages
K&R are stating that goto isn't a requirement in order for the language to be effective, however you're mispresenting K&R's stance by merely quoting only what you did. It's been a long time since I've seen the white bible, but I seem to recall there being two examples where a goto was deemed fine, one was to break out of a doubly nested loop and the other possibly dealing with exceptions.
goto is like anything else in C, it can be abused. Just like pointers.
As always, its best to write things in the least nasty way possible, sometimes that involves a goto.