Link to home
Start Free TrialLog in
Avatar of hxb
hxb

asked on

For .. Next

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
Avatar of jgv
jgv

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'
Avatar of hxb

ASKER

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?


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
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
actually you can take that step out but there is nothing wrong
next i
just tells to pcocess next element.
marine

Tks for pointing it out to me

Ivanc
ASKER CERTIFIED SOLUTION
Avatar of pjknibbs
pjknibbs

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hxb

ASKER

pjknibbs,

Your answner is OK.