Results 1 to 8 of 8

Thread: [RESOLVED] How can i exit out of a For Next loop? Is it possible?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Resolved [RESOLVED] How can i exit out of a For Next loop? Is it possible?

    Is there a way to exit out of a For Next loop? Like

    Code:
    For i = 0 to 5
        If i = 3 then
            'exit loop
        End If
    Next i
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How can i exit out of a For Next loop? Is it possible?

    Code:
    For i = 0 to 5
        If i = 3 then
            Exit For
        End If
    Next i

  3. #3
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How can i exit out of a For Next loop? Is it possible?

    You also have the Exit Do for exiting Do Loops if you ever need it.

  4. #4
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    Re: How can i exit out of a For Next loop? Is it possible?

    Or Exit While for exiting While Loops.

    Exit Sub / Exit Function too

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How can i exit out of a For Next loop? Is it possible?

    Actually, there's no Exit While for While Wend loops in VB6. (but I think there is in .Net, not sure, I don't use it much)

    EDIT: Valid Exits are Do, For, Sub, Function and Property.
    Last edited by baja_yu; May 21st, 2010 at 04:54 PM.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: How can i exit out of a For Next loop? Is it possible?

    Okay. Thanks everyone for your awnseres!
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  7. #7
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: [RESOLVED] How can i exit out of a For Next loop? Is it possible?

    For nested loops, the simplest way is using GoTo, in case you ever run into this problem. You could probably use a boolean check to exit each loop consecutively... but this is probably even less ideal than GoTo.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: [RESOLVED] How can i exit out of a For Next loop? Is it possible?

    So, would this maybe be why this problem of mine happens: http://www.vbforums.com/showthread.p...26#post3806126 ?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

Posting Permissions

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



Click Here to Expand Forum to Full Width