Jumping out of loop with GoTo function

A

Andy

Hi people!

I would like to jump out of a Do loop using the goto statement e.g.

Do Until condition

While i>= 0 And i < value

if value = 1

GoTo Line1:

End If

Wend

Loop

Line1:

Obviously this doesn't do anything, but is the structure correct and
the code correct for the statements shown? Do I need to declare Dim
Line1 as String. My program doesn't work and I think GoTo has something
to do with it not working. I do not have the help file either.

Thank you
 
D

Die_Another_Day

If value = 1 Then 'Forgot the "Then"
GoTo Line1 'No colon needed here

HTH

Charles
 
L

LenB

Hi Andy
If Line1: would be the next statement after Loop, you can use

....
if value = 1 then
Exit Do
End If
Wend
Loop
'goes here if value = 1
.....

Avoid using Goto whenever possible, which is almost always. The only
place it is still needed is "On Error Goto...."

Len
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top