next iteration in VBA

kpark91

Well-known Member
Joined
Jul 15, 2010
Messages
1,582
Hello,
what is the equivalent of continue of C in VBA?

I currently have a code which checks for prime numbers:
Rich (BB code):
Function checkPrime(a As Double) As Boolean
    For n = 2 To Int(Sqr(a))
        If (n Mod 2 = 0 And n <> 2) Then
            Next n
        ElseIf (a Mod n = 0) Then
            checkPrime = False
            Exit Function
        End If
    Next n
    checkPrime = True
End Function

However, I keep getting an error "Compile Error: Next without for"
The red highlighted line seems to be the trouble.

Thank you in advance,
kpark
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
I am afraid that I do not know C, but it appears you may want:
Rich (BB code):
Function checkPrime(a As Double) As Boolean
    For n = 2 To Int(Sqr(a))
        If (n Mod 2 = 0 And n <> 2) Then
            GoTo NextLoop
        ElseIf (a Mod n = 0) Then
            checkPrime = False
            Exit Function
        End If
NextLoop:
    Next n
    checkPrime = True
End Function
 
Upvote 0
You are most welcome; its always nice when its an easy fix:biggrin:
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,285
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top