jump out from a for/next loop


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    60

    Default jump out from a for/next loop

    Hello

    Is this correct if i exit so from a For/next loop

    this code make no sense only to descrive the question

    For i = 1 to 100
    high led
    pause 1000
    low led
    if i >= 30 then exit 'can i jump out from the loop? in other language exixts
    'the instruction "break"
    next

    exit:
    '
    '
    end


    regards

    Pedro

  2. #2
    Join Date
    Sep 2004
    Location
    Mentor, Ohio
    Posts
    352


    Did you find this post helpful? Yes | No

    Smile

    Hi Pedro,

    Why would you set a loop "for i = 1 to 100" if your going to exit the loop after 30 counts? I could possibly understand putting an "if-then" situation in there if you needed to do something based on a condition of another input or something but your example doesn't make any sense.

    BobK

  3. #3
    Join Date
    Jul 2006
    Posts
    60


    Did you find this post helpful? Yes | No

    Default

    Hi BobK

    I said that the example no make sense, the question is if i can without stack
    or other problems jump out of the for/next loop

    again

    For i = 1 To 100
    high led
    pause 200
    low led
    pause 200
    If PORTB.3 = 1 then exit
    next

    exit:

    end


    or is this better?

    For i = 1 To 100
    high led
    pause 200
    low led
    pause 200
    If PORTB.3 = 1 then i = 100
    next


    regards

    Pedro

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Hi Pedro,

    It's perfectly OK to exit a FOR/NEXT loop like in your examples.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. Controlsystem for compact sporting (clay shooting)
    By Fredrick in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2009, 16:48
  2. Serin to Serin2 ??
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 25th January 2008, 03:56
  3. Serial Relays
    By tazntex in forum General
    Replies: 3
    Last Post: - 17th May 2007, 17:42
  4. newbie Q - edge detection?
    By RMCRAVEN in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 9th October 2006, 08:20
  5. Newbie question:
    By Izone in forum mel PIC BASIC
    Replies: 2
    Last Post: - 26th February 2006, 16:24

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