For loop 使用循环递增和递减数字
我正在尝试打印2个数字,从1到150,以及一些文本。 也就是说,第一个范围是从1到150的升序,第二个范围是从150到1的降序。 我可以按升序打印,但我不知道如何按降序打印For loop 使用循环递增和递减数字,for-loop,vbscript,increment,decrement,For Loop,Vbscript,Increment,Decrement,我正在尝试打印2个数字,从1到150,以及一些文本。 也就是说,第一个范围是从1到150的升序,第二个范围是从150到1的降序。 我可以按升序打印,但我不知道如何按降序打印 Set xml = CreateObject("Microsoft.XMLHTTP") For i = 1 to 150 TL1( "HELLO"&i&"INCRESING"&i&";" ) // In both the statement i should increment fro
Set xml = CreateObject("Microsoft.XMLHTTP")
For i = 1 to 150
TL1( "HELLO"&i&"INCRESING"&i&";" ) // In both the statement i should increment from 1 to 150 and
TL1( "HELLO"&n&"INCRESING_I"&i&"DECRESING_N"&n&";" ) // n should decrement from 150 to 1
Next
Set xml = Nothing
Function TL1( cmd )
xml.Open "GET", "http://127.0.0.1:2024/TL1?"&cmd, False
xml.Send
TL1 = xml.responseText
WScript.Stdout.Write cmd & vbCrLf
End Function
所以基本上在for声明之后。i应该递增,n应该递减。有没有办法把这个n加到同一个forloop中 只需计算减少增量值所需的总和,正如评论中所讨论的那样。还要注意使用
Const
来定义常量值,这样当值发生变化时,您就不必通过代码行来调整数值
Const MIN_LOOP = 1
Const MAX_LOOP = 10
Dim i, n
For i = MIN_LOOP To MAX_LOOP
WScript.Echo "HELLO" & i & "INCRESING" & i & ";"
n = (MAX_LOOP + 1) - i
WScript.Echo "HELLO" & n & "INCRESING_I" & i & "DECRESING_N" & n & ";"
Next
输出:
hello1增加1;
他增加了,减少了;
他在增加;
他增加了,减少了;
高增长;
他增加了,减少了;
高增长;
他增加了,减少了;
高增长;
他在增加或减少;
高增长;
他在增加,在减少;
高增长;
他在增加,在减少;
高增长;
他在增加,在减少;
高增长;
他2增加9减少2;
他在增加;
他增加了10减少了1;
在第二个TL1()中使用151-i,而不是仅使用i
在第二个TL1()@RobertAltman中使用150-i而不是仅仅使用i,实际上它应该是
151-i
,因为i
以1@VictorMoraes触摸,先生。接得好@RobertAltman将此作为回答,因为您是第一个在此处发表评论的人:)
Const MIN_LOOP = 1
Const MAX_LOOP = 10
Dim i, n
For i = MIN_LOOP To MAX_LOOP
WScript.Echo "HELLO" & i & "INCRESING" & i & ";"
n = (MAX_LOOP + 1) - i
WScript.Echo "HELLO" & n & "INCRESING_I" & 151 - i & "DECRESING_N" & n & ";"
Next