-2

How do I use/make a goto statement in python 2.7.13. Specifically, what I am trying to do is ask the user to put in an input of a yes or no statement.

If they type in Yes they will continue to there next line but if they answer No I want the user to return to a previous line.

Parfait
  • 104,375
  • 17
  • 94
  • 125
Dylan7299
  • 11
  • 1
  • Possible duplicate of [Is there a label/goto in Python?](http://stackoverflow.com/questions/438844/is-there-a-label-goto-in-python) – jwodder Apr 14 '17 at 20:07

1 Answers1

2

A GOTO statement is a symptom of bad code design. Python is a structured language and lacks this statement, see this post if you want to implement a pseudo GOTO statement.

A better solution is to use better code design with loops or functions:

Loop

while True:
    answer = input("Do you want to continue?")
    if answer == "yes":
        break
print("We are done here!")

Function

def ask_question():
    answer = input("Do you want to continue?")
    if answer == "no":
        ask_question()

ask_question()
print("We are done here!")
Community
  • 1
  • 1
Morgoth
  • 4,935
  • 8
  • 40
  • 66
  • This is a if statement not goto. There are times when goto are the only option –  Dec 02 '17 at 08:44