GOTO vs RETURN after a GOSUB


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: GOTO vs RETURN after a GOSUB

    If you want to be a cowboy for some reason you could have used GOTO instead of GOSUB.
    Then you could GOTO back as well (instead of RETURN).

    The difference between GOTO and GOSUB is that GOSUB loads the stack with the location it was called from so that a RETURN can go back there, but GOTO doesn’t need to do that.

    BUT! using a GOTO to go somewhere, and another GOTO to go back, just means that neither GOTO had to exist, and you could have just dropped the routine right in where the GOTO was.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,132


    Did you find this post helpful? Yes | No

    Default Re: GOTO vs RETURN after a GOSUB

    Also, using GOSUB reduces code size as this Sub can be called from various points of the program to do the same job, maybe with some parameters passing to it.

    Keeps things structured.

    Ioannis

Similar Threads

  1. Is a 'GOTO' Or a 'GoSub'?
    By FromTheCockpit in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st August 2013, 23:27
  2. gosub - return
    By l_gaminde in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 11th August 2010, 10:21
  3. GOTO main or RETURN - Question
    By studysession in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 31st January 2009, 16:13
  4. Return VS Goto?
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th January 2008, 00:13
  5. If ... Then Gosub <> If ... Then Goto?
    By oldtoddler in forum General
    Replies: 6
    Last Post: - 27th February 2006, 11:52

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts