-
Nov 6th, 2007, 01:44 PM
#1
Thread Starter
Hyperactive Member
[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
-
Nov 6th, 2007, 01:58 PM
#2
Re: How do I go to next iteration of For?
I don't understand the logic of your loop.
First, if what is True?
-
Nov 6th, 2007, 01:58 PM
#3
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:
For x = 0 to 10 If true then goto NXTX end if msgbox "hey" NXTX: next x
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 6th, 2007, 01:59 PM
#4
Re: How do I go to next iteration of For?
 Originally Posted by Static
you could use a goto...
Wash your mouth out with soap and then GoTo your room.
-
Nov 6th, 2007, 02:06 PM
#5
Frenzied Member
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:
For x = 0 to 10 If Not true Then MsgBox "hey" End If Next x
-
Nov 6th, 2007, 02:07 PM
#6
Frenzied Member
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
-
Nov 6th, 2007, 02:13 PM
#7
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"
-
Nov 6th, 2007, 03:10 PM
#8
Thread Starter
Hyperactive Member
Re: How do I go to next iteration of For?
 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
-
Nov 6th, 2007, 03:26 PM
#9
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
-
Nov 6th, 2007, 05:50 PM
#10
Re: How do I go to next iteration of For?
vb Code:
Dim i As Long For i = 0 To 10 GoTo Confused: ReallyConfused: Next i GoTo Help Confused: Debug.Print "?"; GoTo ReallyConfused Help:
-
Nov 6th, 2007, 06:06 PM
#11
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
-
Nov 6th, 2007, 06:35 PM
#12
Re: How do I go to next iteration of For?
 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
-
Nov 6th, 2007, 06:52 PM
#13
Thread Starter
Hyperactive Member
Re: How do I go to next iteration of For?
 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
-
Nov 6th, 2007, 07:34 PM
#14
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
-
Nov 7th, 2007, 05:49 AM
#15
Frenzied Member
Re: How do I go to next iteration of For?
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|