首页 > 电脑

为什么VB中提示说next没有for

更新时间2018-03-06 19:58:03

Private Sub Command1_Click()

Dim i As Integer, n As Integer, flag As Boolean

Dim m As Integer

 m = 0

For i = 1001 To 9999 Step 2

n = i

f = True

Do While n > 0

If prime(n) Then

n = n 10

Else

 f = False

 Exit Do

End If

Next i

Label1.Caption = "共有" & Str(m) & "个超级素数"

End Sub

Public Function prime(p As Integer) As Boolean

Dim k As Integer

If p = 1 Then

prime = False

  Exit Function

Else

  For k = 2 To Int(Sqr(p))

 If p Mod k = 0 Then

prime = False

       Exit Function

    End If

  Next k

 End If

prime = True

End Function


Do   缺少  Loop


    For i = 1 To 9999 Step 2

        n = i

        f = True

        Do While n > 0

            If prime(n) Then

                m = m + 1

                n = n 10

            Else

                f = False

                Exit Do

            End If

        Loop

    Next i


上一篇:0x768这个是个什么的内存地址,换算成16进制是什么

下一篇:http://cst2.jlnu.edu.cn/oj/problem.php?id=2006怎么做