Goto

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HMS Surprise

    #1

    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

  • Daniel Nogradi

    #2
    Re: 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.


    Comment

    • Carsten Haese

      #3
      Re: Goto

      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



      Comment

      • HMS Surprise

        #4
        Re: Goto

        Thanks folks!

        jh

        Comment

        • Hendrik van Rooyen

          #5
          Re: Goto

          "HMS Surprise" <john@d...t.com 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.
          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


          Comment

          • Tina I

            #6
            Re: Goto

            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

            Comment

            • John Machin

              #7
              Re: Goto

              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

              Comment

              • Neil Cerutti

                #8
                Re: Goto

                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.

                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

                Comment

                Working...