Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim m As Integer, i As Integer, flag As Boolean
        m = InputBox("请输入一个大于2的整数")
        flag = True       ' 假设m是素数
        For i = 2 To m - 1
            If m Mod i = 0 Then
                flag = False      ' 能被[2, m-1]之间的某个数整除，则m不是素数
                Exit For           ' 终止判别，退出循环
            End If
        Next
        If flag Then      ' 或flag = True，根据flag输出判断结果
            MsgBox(m & "是素数", , "判断素数")
        Else
            MsgBox(m & "不是素数", , "判断素数")
        End If
    End Sub
End Class
