stupid title i know :)
But anyways, is there a way to "go to" a previous line.
something like this:

  1. something
  2. something
  3. something
  4. if a<b:

          (go to) / (do) third line


Recommended Answers

All 12 Replies

Can you explane more what you like to do it?

Use functions and call them.

i can try and give you an example.
i try to count numbers from 1-10. but when I come to number 5 I want it to do something else.
I know I could do this in a milion other ways, but now I can't think of a good example.

i = 0
while i < 10:
    i += 1
    print (i)

    if i == 4:                    # line 6 #
        print ("This number is 4")

    if i == 5:
        i =*2
        check line 6 and continue from there       # this is the part im interested # 

Something like that. Hope that doesn't confuse you even more :)
can you check line 6 with new "i".

Ty again

Mybe you need like that?
i = 0
while i < 10:
    i += 1
    if i == 5:
        #do somthing
        print "Hello World"
        i == 6
        print i

">>> ================================ RESTART ================================
Hello World
>>> "

@tony75, what is line 10 going to do?

There is no goto in Python. Design your program properly and you don't need this old Basic Language horror.

ty, I will try using definitions :D
Why exaclly is this horror?
Im trying to understand this as well as I can.

Ok vegaseat.

If you ever have to maintain somebody else's program code, then goto's are one horror.

Koljik can you give us one meaningful reason why you want to use the goto statement?

Python does have a goto add on Click Here but it was an April Fool's joke so I don't know if it works or not (and don't care as I will not be using it).

We are here to lean python programming not to joke.

I wasn't joking.
I guess this doestn matter because there are other better ways to do it.
I just thaught I could do something in this way but definitions are actually very good :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.