When I wrote "QWERTY password: Encryption and decryption" Yesterday, I wrote this for Next loop in order to get a 26-letter string:
Copy Code code as follows:
' Author:demon
' website:http://demon.tw
' DATE:2012/2/10
For i = (i + 25)
s = S & Chr (i)
Next
WScript.Echo S
After running but found that there is no string output, it is very strange, so a simple change:
Copy Code code as follows:
' Author:demon
' website:http://demon.tw
' DATE:2012/2/10
For i = (i + 25)
WScript.Echo Chr (i)
s = S & Chr (i)
Next
WScript.Echo S
There is still no output indicating that the statement in the for Next loop was not executed at all, and puzzled, and consulted the evening prophet, who soon found the trap:
Copy Code code as follows:
' Author:demon
' website:http://demon.tw
' DATE:2012/2/10
For i = Step-1 (i +)
WScript.Echo Chr (i)
s = S & Chr (i)
Next
WScript.Echo S
This time the species finally has the output, believe that smart you must have found the trap where. The order of the For Next loop is not evaluated from left to right, and the expression (i + 25) is evaluated before i = 65, and the value of I is the default of 0, so the original loop is equivalent to:
Copy Code code as follows:
' Author:demon
' website:http://demon.tw
' DATE:2012/2/10
For i = 25
s = S & Chr (i)
Next
WScript.Echo S
Of course there is no output, and finally I changed the program to this:
Copy Code code as follows:
' Author:demon
' website:http://demon.tw
' DATE:2012/2/10
For i = ASC ("A") to ASC ("Z")
s = S & Chr (i)
Next
WScript.Echo S
It's straightforward and does not run into the for Next trap.