我优化了代码如下:
程序代码:
Option Explicit Private Sub Form_Click() Form1.Cls Dim a As Long, b As Long, c As Boolean Dim n As Integer For a = 2 To 100 c = False For b = 2 To a / 2 '不需要倒循环,另循环只需到循环到一半就可以了 If a Mod b = 0 Then ' c = True Exit For End If Next b If Not c Then '逻辑判断,不要用 是否等于 FLASH ,直接用值判断 If a < 10 Then '小于10,补个格式,为了对齐 Print " "; a; Else Print a; End If n = n + 1 ' If n = 5 Then '显示了5个,就换下行 ,重新计数,比 求余速度更快 Print '换行, n = 0 '重新计数 End If End If Next a End Sub