asp for next步长

来源:百度知道 编辑:UC知道 时间:2024/05/05 21:39:40
for next语句中间可以加入step
不明白step是怎么个用处.
还有,是怎么一个用法.

用处啊?比如说你有一个数字序列,从1到100,你要显示奇数的话就能用上step:
for i=1 to 100 step 2
response.write i
next

step是步长,就是增量的意思,上面的代码是说:i的增量为2,也就是1,3,5,7,9,...,增量也可以为负数,如-2

for i=0 to 100 step 4
'循环块

next
'等于
for i=0 to 100
i=i+4
next

那个step就是每次循环变量(i)的变化量
for i=1 to 100 step 2
表示每次循环i增加4
for i=1 to 100 step 1
如果是这样可简写为 for i=1 to 100