In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shares with you the details of what you need to pay attention to in the VBS For Next loop. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The basic structure of the For Next statement is:
The code is as follows:
For counter = start To end [Step step]
[statements]
[Exit For]
[statements]
Next
When the For Next loop starts, Visual Basic Scripting Edition (VBScript) assigns start to counter. Compare counter to end before running the statement block in the loop. If counter has exceeded the value of end, the For loop terminates and the control flow jumps to the statement after Next. Otherwise, run the statement block in the loop.
Every time VBScript encounters Next, it increments counter by step and returns it to For. It compares the values of counter and end again and continues to run the block of statements in the loop or terminates the loop based on the result. This process continues until counter exceeds end or encounters an Exit For statement.
The above is common sense. Here is a detail you may have overlooked.
The loop control variables start end and step are evaluated only once before the loop starts. If you change the value of end or step in the block of statements in the loop, this change will not affect the operation of the loop.
Write a simple VBS script to verify:
The copy code is as follows:
'Author: Demon
'Date: 2012-1-19
N = 10
S = 1
For I = 1 To n Step s
WScript.Echo i
N = 5
S = 2
Next
WScript.Echo n, s
We changed the values of n and s in the loop, but the loop still went on 10 times, outputting 1 to 10 in turn, indicating that there is a copy of the loop control variables n and s in the For Next loop, and the internal variables are used to control the flow of the loop.
Knowing this detail will help us write efficient and concise code:
The copy code is as follows:
'Author: Demon
'Date: 2012-1-19
S = "http://jb51.net"
For I = 1 To Len (s)
WScript.Echo Mid (s, I, 1)
Next
This kind of C Style is no more efficient than the above
'you don't need to do this in the For Next loop of VBS
L = Len (s)
For I = 1 To l
WScript.Echo Mid (s, I, 1)
Next
It is worth noting that changing the counter in the loop is allowed, but you should avoid doing so, as this will only make your script difficult to read and debug.
The copy code is as follows:
'Author: Demon
'Date: 2012-1-19
For I = 1 To 10
WScript.Echo i
I = I + 2 'does not encourage this.
Next
Thank you for reading! This is the end of this article on "what details do you need to pay attention to in the VBS For Next cycle"? I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.