Is there a penalty for breaking early out of a For Loop with a Goto Statement?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2004
    Posts
    46

    Default Is there a penalty for breaking early out of a For Loop with a Goto Statement?

    I have a For Loop nested inside another For Loop and there will be times that I want to break out of the inner loop and outer loop before either of them finish.
    Can one do this with a GoTo without causing a value to remain on the stack or blow up my program later on?
    Last edited by khufumen; - 14th October 2016 at 16:56.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,557


    Did you find this post helpful? Yes | No

    Default Re: Is there a penalty for breaking early out of a For Loop with a Goto Statement?

    With a GOTO, yes I don't see a problem with that. Another option might be to "manually" set the index variable so that the loop ends when the current iterations is finished.

    /Henrik.

  3. #3
    Join Date
    Sep 2009
    Posts
    748


    Did you find this post helpful? Yes | No

    Default Re: Is there a penalty for breaking early out of a For Loop with a Goto Statement?

    You can also use EXIT.

  4. #4
    Join Date
    Oct 2004
    Posts
    46


    Did you find this post helpful? Yes | No

    Default Re: Is there a penalty for breaking early out of a For Loop with a Goto Statement?

    Thank you for your help.
    I wasn't aware of the Exit command.
    Answers my question.

    You guys really rock in terms of your support and patience for us newbies!

Similar Threads

  1. Exit from an IF/ENDIF loop with a GOTO
    By aratti in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 17th February 2014, 13:05
  2. early power down
    By iw2fvo in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 21st August 2009, 14:06
  3. Am I stupid? Goto does not GOTO??? Where's the bug??
    By xnihilo in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 15th October 2008, 10:31
  4. Breaking out of for loops
    By Kamikaze47 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th March 2008, 00:49
  5. Breaking through pages in PIC16 Series
    By crematory in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 1st August 2005, 13:49

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