VB中for循环的问题
我刚开始学VB碰到for循环的时候写了一句……Sub……Dimaaslongfora=1to10nextmessage.text=&aEndSub……结果页面上打印出来的...
我刚开始学VB
碰到for循环的时候写了一句
……
Sub……
Dim a as long
for a=1to 10
next
message.text=& a
End Sub
……
结果页面上打印出来的a值为11!
提请高明释疑。 展开
碰到for循环的时候写了一句
……
Sub……
Dim a as long
for a=1to 10
next
message.text=& a
End Sub
……
结果页面上打印出来的a值为11!
提请高明释疑。 展开
11个回答
展开全部
首先你要明白FOR循环的过程,
第一步:自变量A加1,
第二步:用自变量与10进行比较,如A<=10那边进入循环体,否则退出
所以当A=10时,循环做最后一次,然后再加1与10比较,发现大于10,这才结束循环,所以此时A=11
第一步:自变量A加1,
第二步:用自变量与10进行比较,如A<=10那边进入循环体,否则退出
所以当A=10时,循环做最后一次,然后再加1与10比较,发现大于10,这才结束循环,所以此时A=11
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim
i
As
Integer
Dim
a
As
Integer
Dim
n
As
Integer
Dim
sum
As
Integer
Dim
s
As
Integer
a
=
2
n
=
5
sum
=
0
s
=
0
For
i
=
1
To
n
sum
=
sum
+
2
*
10
^
(i
-
1)
'获得每一个数
s
=
s
+
sum
'把n个数加起来
Next
Print
s
====================================
'根据观察,总和可以看成有1个20000、2个2000…5个2组成
Dim
i
As
Integer
Dim
a
As
Integer
Dim
n
As
Integer
Dim
s
As
Integer
a
=
2
n
=
5
s
=
0
For
i
=
1
To
n
s
=
s
+
2
*
10
^
(i
-
1)
*
(n
-
i
+
1)
Next
Print
s
=================================
你要那么多答案干什么,都蛮好看懂的啊,我给你简单注释一下吧
i
As
Integer
Dim
a
As
Integer
Dim
n
As
Integer
Dim
sum
As
Integer
Dim
s
As
Integer
a
=
2
n
=
5
sum
=
0
s
=
0
For
i
=
1
To
n
sum
=
sum
+
2
*
10
^
(i
-
1)
'获得每一个数
s
=
s
+
sum
'把n个数加起来
Next
s
====================================
'根据观察,总和可以看成有1个20000、2个2000…5个2组成
Dim
i
As
Integer
Dim
a
As
Integer
Dim
n
As
Integer
Dim
s
As
Integer
a
=
2
n
=
5
s
=
0
For
i
=
1
To
n
s
=
s
+
2
*
10
^
(i
-
1)
*
(n
-
i
+
1)
Next
s
=================================
你要那么多答案干什么,都蛮好看懂的啊,我给你简单注释一下吧
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
因为你的循环变量a是整型,不会去验证-6.5。你可以改成单精度类型,步长改为0.5
private
sub
form_click()
dim
a
as
single
for
a
=
-100
to
100
step
0.5
if
2
*
a
^
2
+
3
*
a
+
6
=
71
then
print
a
/
100
print
"a=";
a
end
if
next
a
end
sub
private
sub
form_click()
dim
a
as
single
for
a
=
-100
to
100
step
0.5
if
2
*
a
^
2
+
3
*
a
+
6
=
71
then
a
/
100
"a=";
a
end
if
next
a
end
sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
dim
a
as
string
dim
n
as
integer
dim
k
as
string
dim
s
as
integer
a="2"
n=5
s=0
for
i
as
integer
=1
to
n
for
j
as
integer=1
to
i
k=k
&
a
next
s=s+cint(k)
next
或者
下边的容易,易理解
dim
b
as
integer
dim
a
as
integer
dim
n
as
integer
dim
s
as
integer
b=0
a=2
n=5
s=0
for
i
as
integer=1
to
n
b=b*10
+2
s=s+b
next
方法有很多种,但都脱离不了这两种思想。要想要别的,自己组合一下就可以了
a
as
string
dim
n
as
integer
dim
k
as
string
dim
s
as
integer
a="2"
n=5
s=0
for
i
as
integer
=1
to
n
for
j
as
integer=1
to
i
k=k
&
a
next
s=s+cint(k)
next
或者
下边的容易,易理解
dim
b
as
integer
dim
a
as
integer
dim
n
as
integer
dim
s
as
integer
b=0
a=2
n=5
s=0
for
i
as
integer=1
to
n
b=b*10
+2
s=s+b
next
方法有很多种,但都脱离不了这两种思想。要想要别的,自己组合一下就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询