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?
#11
In the 70's, most microcomputer code was Basic until the advent of forth (which followed shortly thereafter)
I admit, I used it. I wanted to get things done. It was free even then! and I was poor!

I also wrote extensively in assembler (6502, 8080, 6800).
Then forth which I was passionate about.
Reply
#12
(Apr-21-2017, 12:59 AM)micseydel Wrote:
(Apr-20-2017, 10:41 PM)Larz60+ Wrote: Thank God No!
Being a benevolent dictator for life does not make one a god!

That's why I thanked BDFL  Cool

(Apr-21-2017, 05:32 AM)Larz60+ Wrote: In the 70's, most microcomputer code was Basic until the advent of forth (which followed shortly thereafter)
In 1986 I started on a Soviet clone (pirated, of course) of Wang2200. The bloody thing didn't even have procedure/functions  Cry . Then I had to translate it into Pascal on 48K clone of some Japanese microcomp. The joys of segmenting and overloading code Evil
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
#13
(Apr-21-2017, 04:46 AM)Luke_Drillbrain Wrote: I did find it useful for certain things.  One was for when I was still in the early stages of creating a loop and wanted to avoid an endless loop and a crash.  I could set an integer to track the number of times something looped, and then set a place outside the loop named "JumpOut".  If the integer got higher than 1,000 (or some other value), "GoTo JumpOut" would be triggered and the loop would end. 

(...)

Another one was "On Error Resume Next."  That was useful to keep code running while searching for errors, but I would remove it after errors were found and fixed. 

I'll keep learning.  I'm sure I'll come across a lot of great debugging tricks in time.  Thank you so much for your useful comments.

You may want to look into python break and try/except constructs
Reply
#14
(Apr-21-2017, 08:24 AM)Kebap Wrote:
(Apr-21-2017, 04:46 AM)Luke_Drillbrain Wrote: [snip]

You may want to look into python break and try/except constructs

I'll look those up.  Thanks for the tip.
Reply
#15
(Apr-21-2017, 04:46 AM)Luke_Drillbrain Wrote: One was for when I was still in the early stages of creating a loop and wanted to avoid an endless loop and a crash.  I could set an integer to track the number of times something looped, and then set a place outside the loop named "JumpOut".  If the integer got higher than 1,000 (or some other value), "GoTo JumpOut" would be triggered and the loop would end.  

I don't see how that'd be better than just writing a function and using return to get out of the function.  It's the same thing, except with the function it's easier to see what your actual intention is.
Reply
#16
Quote:If the integer got higher than 1,000 (or some other value), "GoTo JumpOut" would be triggered and the loop would end.
To add some advice to what's alreay mention
Using Function/Class can be important to think of,
example in a function you can return out.
This can be nicer than break/continue to other stuff.

A example:
So here jump to function foo,
after foo is finish it will fall back to menu which can run again or quit(return) out.
import time

def foo():
   for i in reversed(range(5)):
       time.sleep(1)
       print('Running {}'.format(i))
   input('Push enter to retun to menu')

def menu():
   while True:
       print('(1) Test someting')
       print('(Q) Quit')
       choice = input('Enter your choice: ').lower()
       if choice == '1':
           foo()
       elif choice == 'q':
           return 
       else:
           print('Not a correct choice: {}'.format(choice))

if __name__ == '__main__':
   menu()
Reply
#17
Here's an article from not that long ago detailing NASA's 10 programming rules for safety: http://www.rankred.com/nasa-coding-rules/

#1 is basically never use goto.
Quote:Rule No. 1 – Simple Control Flow
Write program with very simple control flow constructs – Do not use setjmp or longjmp constructs, goto statements, and direct or indirect recursion.

Reason: Simple control flow results in improved code clarity and stronger capabilities for verification. Without recursion, there will be no cyclic function call graph, and this proves that all executions that should be bounded are in fact bounded.
Reply
#18
Not even recursion? That's interesting....
Reply
#19
That doc is probably really old. Guaranteeing something doesn't eat too much memory while careening around the surface of the moon is a little more important that just saying "it's probably going to be fine.".
Reply
#20
Yeah, the article had some good points, but it was clearly about critical systems.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  goto jmabrito 34 10,305 Feb-18-2021, 09:55 PM
Last Post: jmabrito
  How to make input goto a different line mxl671 2 2,470 Feb-04-2020, 07:12 PM
Last Post: Marbelous
  goto problem Skaperen 1 2,742 Jan-27-2018, 01:11 PM
Last Post: stranac
  Go up script/menu(a goto command) foxtreat 7 8,240 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