How does one effect a goto in python? I only want to use it for debug.
I dasn't slap an "if" clause around the portion to dummy out, the
indentation police will nab me.
On Wed, 2007-06-13 at 12:20 -0700, HMS Surprise wrote:
How does one effect a goto in python?
One doesn't.
I only want to use it for debug.
I dasn't slap an "if" clause around the portion to dummy out, the
indentation police will nab me.
If you want to disable a code block without indenting it into an "if
False:" block, use triple quotes, either ''' or """, to turn it into a
long string.
>
How does one effect a goto in python? I only want to use it for debug.
I dasn't slap an "if" clause around the portion to dummy out, the
indentation police will nab me.
I use a global boolean called trace:
if trace:
do debug stuff
But to try to answer your question:
There are two gotos in standard Python.
They are spelled:
"continue" and "break"
The first jumps to the start of a loop, and the last to after the end of one.
Anything more fancy is "Verboten" - except, that, if you ask nicely,
John Machin might explain his comefrom construct.
And maybe I will understand it this time around...
>How does one effect a goto in python? I only want to use it for debug.
>I dasn't slap an "if" clause around the portion to dummy out, the
>indentation police will nab me.
LOL!! * major flashback to horrible BASIC programs from the eighties *
Back then I took a course in structured BASIC programming (now there is
a contradiction in terms) and the instructor warned about goto time and
time again. But his biggest mistake was to tell us that if we had to use
goto at least we should explain it in a comment. So we would turn in
programs with sections like:
100 IF S$="YES" THEN GOTO 150
110 REM Go to line 150 if S$ is Yes
On Jun 14, 4:32 pm, "Hendrik van Rooyen" <m...@microcorp .co.zawrote:
[snip]
>
Anything more fancy is "Verboten" - except, that, if you ask nicely,
John Machin might explain his comefrom construct.
>
And maybe I will understand it this time around...
Hendrik, if you google for 'comefrom' in this newsgroup, you will get
several threads. However if you google for 'Machin comefrom' the only
hit is the above posting. You must be confusing me with somebody else.
Cheers,
John
On 2007-06-17, Tina I <tinaweb@bestem selv.comwrote:
Back then I took a course in structured BASIC programming (now
there is a contradiction in terms) and the instructor warned
about goto time and time again. But his biggest mistake was to
tell us that if we had to use goto at least we should explain
it in a comment. So we would turn in programs with sections
like:
>
100 IF S$="YES" THEN GOTO 150
110 REM Go to line 150 if S$ is Yes
Once I learned GOSUB (in Commodore BASIC) I used it instead of
GOTO all the time. I used it for functions long before I learned
about functions in Programming 101.
Comment