471,337 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

Goto


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

Jun 13 '07 #1
7 1454
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.

http://entrian.com/goto/
Jun 13 '07 #2
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.

HTH,

--
Carsten Haese
http://informixdb.sourceforge.net
Jun 13 '07 #3
Thanks folks!

jh

Jun 13 '07 #4
"HMS Surprise" <john@d...t.comwrote:

>
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
Jun 14 '07 #5
Daniel Nogradi wrote:
>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.


http://entrian.com/goto/
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
Jun 17 '07 #6
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

Jun 17 '07 #7
On 2007-06-17, Tina I <ti*****@bestemselv.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.

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.

--
Neil Cerutti
Jun 17 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

30 posts views Thread by Hayri ERDENER | last post: by
51 posts views Thread by WindAndWaves | last post: by
37 posts views Thread by Tim Marshall | last post: by
52 posts views Thread by Rick | last post: by
45 posts views Thread by Debashish Chakravarty | last post: by
77 posts views Thread by M.B | last post: by
34 posts views Thread by electrician | last post: by
3 posts views Thread by electrician | last post: by
59 posts views Thread by raashid bhatt | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.