Goto

H

HMS Surprise

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.

Thanx,

jh
 
C

Carsten Haese

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.

HTH,
 
H

Hendrik van Rooyen

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...

- Hendrik
 
T

Tina I

Daniel said:
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


Tina
 
J

John Machin

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
 
N

Neil Cerutti

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.

100 NAME$="TED"
110 AGE=40
120 GOSUB 1000


1000 PRINT NAME$, " IS ", AGE, " YEAR(S) OLD."
1010 RETURN

Named functions are so much nicer than numbered ones.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top