VB中计算1到100的和,,当和大于2000时终止循环(使用循环退出语句Exit For)

求大神,在线等~
2025-03-03 10:44:05
推荐回答(2个)
回答1:

Private Sub Form_Click()
For i = 1 To 100
a = a + i
If a > 2000 Then
Exit For
End If
Next
Print a
Print i
End Sub

回答2:

dim i as integer
dim s as integer
for i= 1 to 100
s=s+i
if s>2000 then exit for
next
print s