谢绝使用Goto语句,请求大妈解决。
'谢绝使用Goto语句,请求高人指点迷津!
'欢迎光临,但是请不要改的面目全非。。
Private Sub Test() Dim k&, i&, N& ColumnAddr% = 0 N = InputBox("请输入查找质数的范围", "输入大于二的整数") MsgBox "这种算法求质数较慢,请稍后...", , "提示" For k = 2 To N Step 1 For i = 2 To Fix(Sqr(k)) If k Mod i = 0 Then GoTo 10 'Next i '此处怎么使得Next i 生效,Without using "Goto" End If Next i Form1.Print k, ColumnAddr = ColumnAddr + 1 If ColumnAddr = 4 Then ColumnAddr = 0: Form1.Print10: Next kEnd Sub
Private Sub Test() Dim k&, i&, N& ColumnAddr% = 0 N = InputBox("请输入查找质数的范围", "输入大于二的整数") MsgBox "这种算法求质数较慢,请稍后...", , "提示" For k = 2 To N Do For i = 2 To Fix(Sqr(k)) 'If k Mod i = 0 Then ' GoTo 10 ' 'Next i '此处怎么使得Next i 生效,Without using "Goto" 'End If ' 应该是使 Next k 生效吧! If (k Mod i = 0) Then Exit Do Next Form1.Print k, ColumnAddr = ColumnAddr + 1 If ColumnAddr = 4 Then ColumnAddr = 0: Form1.Print Loop While (False)'10: NextEnd Sub
[解决办法]
Private Sub Test() Dim zs