VB 用exit do语句,产生随机的两位数,当偶数的个数为6的时候结束。

2024-11-07 18:28:55
推荐回答(3个)
回答1:

Private Sub Form_Click()
Static i As Integer
Static j As Integer
Static k As Integer
k = 0
j = 0
Me.Cls
Randomize
Do
k = k + 1
i = (Rnd() * 90 + 10) Mod 100
Me.Print i;
If i Mod 2 = 0 Then
j = j + 1
Me.Print "*"
Else
Me.Print
End If
If j = 6 Then Exit Do
DoEvents
Loop While 1
Me.Print "共产生了" & k & "个随机数"
End Sub

回答2:

Option Explicit

Sub test()
Dim i As Integer, tem As Integer
Do
tem = Int(Rnd * 100)
If tem Mod 2 <> 0 Then tem = tem + 1
i = i + 1
If i > 6 Then Exit Do
Print tem
Loop
End Sub

回答3:

那就用EXIT DO做啊,FOR,WHILE,DO。。。WHILE,看一下这几个循环用法就知道了