早教吧 育儿知识 作业答案 考试题库 百科 知识分享

谁能帮我解释一下这是怎么算出来的2557PrivateSubCommand1Click()DimiAsInteger,sAsIntegeri=1DoWhile(i<10)s=s+iIfs>1Ands<8ThenPrintsElses=0EndIfi=i+1LoopEndSub

题目详情
谁能帮我解释一下这是怎么算出来的 2557
Private Sub Command1_Click()
Dim i As Integer, s As Integer
i = 1
Do While (i < 10)
s = s + i
If s > 1 And s < 8 Then
Print s
Else
s = 0
End If
i = i + 1
Loop
End Sub
▼优质解答
答案和解析
一段不难的basic语言写的程序
初始:i=1 s=0
第1次结束:s=0 i=2(No print because of s=1,and then s=0)
2 :s=2 i=3(Print 2)
3 :s=5 i=4(Print 5)
4 :s=0 i=5(First,s=9 then no print and s=0)
5 :s=5 i=6(Print 5)
6 :s=0 i=7(s=11 then no P and s=0)
7 :s=7 i=8(Print 8)
......(s always bigger than 8)
9 :s=0 i=10(Exit)