用VB的6种循环语句分别编程实现10!

如题所述

第1个回答  推荐于2016-06-20
第一种用for...next 循环
Private Sub CommandButton1_Click()
dim i as integer

dim jc as double
jc=1
for i=10 to 1 step -1
jc=jc*i
next i
print "10!=“;
print jc
End Sub
第二种用当循环while...wend
Private Sub CommandButton1_Click()
dim i as integer

dim jc as double
jc=1
i=10
while i>=1
jc=jc*i
i=i-1
wend
print "10!=“;
print jc
End Sub
第三种用do循环do...loop
(1)do...loop while
Private Sub CommandButton1_Click()
dim i as integer

dim jc as double
jc=1
i=10
do
jc=jc*i
i=i-1
loop while i>=1
print "10!=“;
print jc
End Sub
(2)do...loop until
Private Sub CommandButton1_Click()
dim i as integer

dim jc as double
jc=1
i=10
do
jc=jc*i
i=i-1
loop until i<1
print "10!=“;
print jc
End Sub
(3)do while...loop
Private Sub CommandButton1_Click()
dim i as integer

dim jc as double
jc=1
i=10
do while i>=1
jc=jc*i
i=i-1
loop
print "10!=“;
print jc
End Sub
(4)do until...loop
Private Sub CommandButton1_Click()
dim i as integer

dim jc as double
jc=1
i=10
do until i<1
jc=jc*i
i=i-1
loop
print "10!=“;
print jc
End Sub本回答被提问者采纳
相似回答