Solved

For .. Next

Posted on 2000-02-22
8
187 Views
Last Modified: 2010-05-02
VB6,
How to goto the next loop in
"For.. Next" and skip the other
code?

For example:
For i=1 to 100
   j=6
   k=10
   if blnYes=true then
     'Here how to skip the code
     ' of k=k+j ... and let it
     ' execute Next i?
   endif
   k=k+j
   
next i
0
Comment
Question by:hxb
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 12

Expert Comment

by:jgv
ID: 2548927
If blnYes = False Then k = k + j

or

If blnYes = True Then
   'do some code
Else
   k=k+j
End If

or use a 'goto'
0
 

Author Comment

by:hxb
ID: 2549008
Same question about
Do while true
Loop

I know I can use "If Then" and "GOTO"
But is there any other simple Code
such as "Loop" or Other Code I
can Use?


0
 
LVL 6

Expert Comment

by:Marine
ID: 2549067
Same applies to both do while and to For.
For i = 0 to 10
if i = 3 then
exit for
end if
next

i = 0
do while i < 10
 i = i + 1
 if i =5 then
   exit do
  end if
loop
0
 
LVL 3

Expert Comment

by:ivanc
ID: 2549117
HXB

I am not so sure about your qn but your syntax is slightly wrong.  it should be

For i =1 to 100
..
..
..
..
next

There should not be a next i

Hope this helps

Ivanc
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Expert Comment

by:Marine
ID: 2549128
actually you can take that step out but there is nothing wrong
next i
just tells to pcocess next element.
0
 
LVL 3

Expert Comment

by:ivanc
ID: 2549135
marine

Tks for pointing it out to me

Ivanc
0
 
LVL 12

Accepted Solution

by:
pjknibbs earned 50 total points
ID: 2549515
One of the most annoying features of Visual BASIC is its lack of a CONTINUE option on For loops. The only way you can go to the next iteration of a loop is to insert a GOTO label, and put the label on the "NEXT" line of your loop. Maybe Microsoft will add this in version 7... <sigh>
0
 

Author Comment

by:hxb
ID: 2549631
pjknibbs,

Your answner is OK.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel Vlookup to move data back to source. 4 84
Concatenate 2 userform comboboxes to a userform text box 4 56
Adding to a VBA? 6 63
using web browser with BING 40 111
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now