Python Forum
Is there a goto like there is in BASIC?
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a goto like there is in BASIC?
#2
BDFL forbids - no GOTO You just put this block into a loop - one variant is infinite loop

while True:
    if <bla-bla-bla>:
    .......
    else:
        print('You chose wrong')
        continue
    break
Unless you make a legal choice, your code will fall through to the final else, where continue will force the loop to return to beginning. On legal choice, loop will be ended by break
Test everything in a Python shell (iPython, Azure Notebook, etc.)
  • Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
  • Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
  • You posted a claim that something you did not test works? Be prepared to eat your hat.
Reply


Messages In This Thread
RE: Is there a goto like there is in BASIC? - by volcano63 - Apr-20-2017, 09:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  goto jmabrito 34 10,711 Feb-18-2021, 09:55 PM
Last Post: jmabrito
  How to make input goto a different line mxl671 2 2,521 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  goto problem Skaperen 1 2,793 Jan-27-2018, 01:11 PM
Last Post: stranac
  Go up script/menu(a goto command) foxtreat 7 8,363 Apr-24-2017, 05:58 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020