PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[Resolved] How do I go to next iteration of For?-VBForums
Results 1 to 15 of 15

Thread: [Resolved] How do I go to next iteration of For?

  1. #1

    Thread Starter
    Hyperactive Member capsulecorpjx's Avatar
    Join Date
    May 2005
    Location
    Renton, WA
    Posts
    288

    [Resolved] How do I go to next iteration of For?

    For x = 0 to 10
    if true then
    next x
    end if
    msgbox "hey"
    next x

    I'm trying to force a for loop to go to the next iteration. But the "next x" doesn't seem to work. What's the right command?
    Last edited by capsulecorpjx; Nov 6th, 2007 at 06:53 PM.
    "I like to run on treadmills, because at least I know I'm getting nowhere."
    - Me

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: How do I go to next iteration of For?

    I don't understand the logic of your loop.

    First, if what is True?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do I go to next iteration of For?

    if true?? if what is true?
    what are you trying to do with that...?

    you could use a goto...

    vb Code:
    1. For x = 0 to 10
    2.   If true then
    3.     goto NXTX
    4.   end if
    5.   msgbox "hey"
    6. NXTX:
    7. next x
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: How do I go to next iteration of For?

    Quote Originally Posted by Static
    you could use a goto...
    Wash your mouth out with soap and then GoTo your room.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: How do I go to next iteration of For?

    GoTo is bad.

    Do you want to do something only if some condtion is not true?
    And otherwise go straight to the end of the loop?
    vb Code:
    1. For x = 0 to 10
    2.     If Not true Then
    3.         MsgBox "hey"
    4.     End If
    5. Next x

  6. #6
    Frenzied Member
    Join Date
    Sep 2006
    Location
    Scotland
    Posts
    1,054

    Re: How do I go to next iteration of For?

    Use this:

    Code:
    For x = 0 To 10
        If variable = True Then
            Exit For
        End If
        MsgBox "hey"
    Next x

  7. #7
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: How do I go to next iteration of For?

    no... ok.. i know goto is bad.. but if its THAT bad.. why do u still use it in On Error Goto..... ???

    O3.. thats no good... that exits the for, they want to just jump to the next x

    I would use Jeroen's idea... basically use if else... so if its Not true then do whatever... else... do this.. so it will skip by everything
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8

    Thread Starter
    Hyperactive Member capsulecorpjx's Avatar
    Join Date
    May 2005
    Location
    Renton, WA
    Posts
    288

    Re: How do I go to next iteration of For?

    Quote Originally Posted by Static
    no... ok.. i know goto is bad.. but if its THAT bad.. why do u still use it in On Error Goto..... ???

    O3.. thats no good... that exits the for, they want to just jump to the next x

    I would use Jeroen's idea... basically use if else... so if its Not true then do whatever... else... do this.. so it will skip by everything
    I'm gonna use the If / Else. I wanted to try to avoid that just to keep the number of tabs down and make the code look cleaner.

    GoTo would be the good option, but I want to try to avoid using it as it is not supported in VB.NET, and we might convert in the future.
    "I like to run on treadmills, because at least I know I'm getting nowhere."
    - Me

  9. #9
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,293

    Re: How do I go to next iteration of For?

    OEGT is still used because they haven't given us anything better to use. However, OEGT isn't a true GoTo, it simply is part of the construct. But using GoTo by itself like that.... I cringe when I keep reading "... and GoTo is still supported in this version of VB...." ... Personally I wished they had excised it years ago...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  10. #10
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: How do I go to next iteration of For?

    vb Code:
    1. Dim i As Long
    2.    For i = 0 To 10
    3.       GoTo Confused:
    4. ReallyConfused:
    5.    Next i
    6.    GoTo Help
    7. Confused:
    8.    Debug.Print "?";
    9.    GoTo ReallyConfused
    10. Help:

  11. #11
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,293

    Re: How do I go to next iteration of For?

    milk - that truly deserves to be immortalized here: http://www.vbforums.com/showthread.php?t=495402

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  12. #12
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    18,218

    Re: How do I go to next iteration of For?

    Quote Originally Posted by capsulecorpjx
    For x = 0 to 10
    if true then
    next x
    end if
    msgbox "hey"
    next x

    I'm trying to force a for loop to go to the next iteration. But the "next x" doesn't seem to work. What's the right command?
    What about something as simple as:
    Code:
    For X = 0 To 10
       If True Then 
           X = X + 1
       Else
          MsgBox "Hey"
       End If
    Next X

  13. #13

    Thread Starter
    Hyperactive Member capsulecorpjx's Avatar
    Join Date
    May 2005
    Location
    Renton, WA
    Posts
    288

    Re: How do I go to next iteration of For?

    Quote Originally Posted by LaVolpe
    What about something as simple as:
    Code:
    For X = 0 To 10
       If True Then 
           X = X + 1
       Else
          MsgBox "Hey"
       End If
    Next X
    That would actually go through the loop twice as fast, cause Next X is also X = X+1.

    I just went with
    Code:
    For X = 0 to 10
       If <condition> Then
            strErrMsg= strErrMmsg & vbNewLine & "Line " & X & " has an issue"
       Else
            <statements>
       End If
    Next X
    "I like to run on treadmills, because at least I know I'm getting nowhere."
    - Me

  14. #14
    Super Moderator Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [Resolved] How do I go to next iteration of For?

    Or....
    Code:
    For x = 1 To 10
        If IfeltTheNeedToUseGotoHere = False Then
            'do the work
        End If
    Next
    No goto but whenever I felt the need to use it was true, it simply jumped down to the Next statement anyway.
    Last edited by Joacim Andersson; Nov 6th, 2007 at 07:38 PM.
    Joacim Andersson
    If anyone's answer has helped you, please show your appreciation by rating that answer.
    I'd rather run ScriptBrix...
    Joacim's view on stuff.

    MVP

  15. #15
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: How do I go to next iteration of For?

    Quote Originally Posted by 03myersd
    Use this:

    Code:
    For x = 0 To 10
        If variable = True Then
            Exit For
        End If
        MsgBox "hey"
    Next x
    Exit For will terminate the entire loop, including any iterations you did not yet do.
    If you just want to skip to the next iteration then this will be too much.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width