On Wed, 15 Jun 2016 09:19 pm, Rustom Mody wrote: > On Wednesday, June 15, 2016 at 8:42:33 AM UTC+5:30, Steven D'Aprano wrote: >> On Wed, 15 Jun 2016 01:33 am, Rustom Mody wrote: [...] >> > And break is a euphemism for goto >> >> Sort of. A break is a jump, and a goto is a jump, but apart from that, >> they're not really the same thing. A goto can jump (almost) anywhere. >> Depending on the language, they can jump into the middle of functions, or >> into the middle of loops. That's what makes them powerful enough to break >> compositionality. But break can only jump to a single place: to the >> statement that follows the for...else compound statement. It's more like >> a return than a goto. > > I thought there'd be many examples for showing that break is just goto in > disguise... Evidently not > > So here is an example in more detail for why/how break=goto: > > http://blog.languager.org/2016/06/break-is-goto-in-disguise.html
Quote: "For now lets just agree that break is not very different from goto" Let's not. Your argument seems to be: "I can use GOTO to jump outside of a loop. I can use BREAK to jump outside of a loop. Careless use of jumping out of a loop leads to a bug, regardless of whether that jump is written as GOTO or BREAK. Therefore GOTO and BREAK are the same thing." but you have failed to consider: "I can use GOTO to jump inside a loop. I *cannot* use BREAK to jump inside a loop. I can use GOTO to jump back to before the loop. I *cannot* use BREAK to jump back before the loop. In the most general case of completely unstructured programming, I can use GOTO to jump I can use GOTO to jump out of one function into the middle of another function, or any other arbitrary line of code anywhere in my program. I *cannot* do the same with BREAK." If you only consider the similarities, and not the differences, you would erroneously conclude that all sorts of things that are actually quite different are "similar". "Cars are actually not so different from the Space Shuttle. Here's video of the shuttle taxiing down the runway after returning from space. Here's a video of a car driving along a road. Careless driving can run over pedestrians, regardless of whether you are driving a car or taxiing a space shuttle. Therefore cars and space shuttles are not that different." Congratulations, you have discovered that mechanically replacing careless use of GOTO with careless use of BREAK doesn't necessarily make the code less buggy. That's a valuable lesson for cargo-cult programmers who think that its the *word* "goto" that causes bad things to happen, and changing the word magically will fix the bug. But to the rest of us, it's about as insightful as the discovery that mechanically replacing "x*5" with "x+x+x+x+x" won't fix the off-by-one error that you actually needed "x*6". -- Steven -- https://mail.python.org/mailman/listinfo/python-list