# Visual Basic > Office Development >  Error that makes absolutely no sense - please help!

## groston

I have been programming for a few years and feel that I can generally get things done. However, I just ran into a problem in Excel VBA that makes literally no sense to me. Here is the code (simplified to just show the issue):


```
Sub testme()
    Dim i, j As Integer
    For i = 1 To 10
        Do
        While j > 5
    Next i  ** this line
End Sub
```

When I click Debug->Compile VBA Project, it shows: Compile error: Next without For on the line indicated.

This makes less than no sense as the code is perfectly reasonable. What the heck is going on??? More importantly, how can I use this trivial construct in my code and make it work?

----------


## OptionBase1

Should be:



```
Do
Loop While (Condition)
```

----------


## OptionBase1

Just to add some clarity to what is happening here, a standalone "While" statement is not valid syntax to close a Do loop.  A standalone "While" statement is actually the beginning statement of a While-Wend loop.

So, properly indenting your code to reflect what is actually happening, this is effectively what you have:



```
Sub testme()
    Dim i, j As Integer
    For i = 1 To 10
        Do
            While j > 5
                Next i  ** this line
End Sub
```

So, from this, it should be clear why a Next without For statement is encountered.

----------


## groston

doh!!! I forgot Loop - thanks!

----------


## jmcilhinney

If your issue has been resolved, please use the Thread Tools menu to mark the thread Resolved, so we can see that you need no more help without opening the thread and reading it.

----------

