In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to use vbscript to calculate the sum of 1 to 100. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
We seldom use new Array to define arrays. Unexpectedly, new Array has such a wonderful use. Through new Array (n), we can create n empty elements, and at the same time, there is a blank space among n elements. Through join, we can put something in the middle of these blanks to form a special string we need, which inspired me. This feature makes it easy for me to achieve a "continuous operation of regular elements" without a loop. For example, to calculate the sum of values from 1 to 100. In the past, we needed to loop from 1 to 100 and then sum, but with this feature of the array, we can do it with a simple line of code, as follows:
The copy code is as follows:
Var iMagne summation eval ('0'+new Array (101) .join (' + (+ I)'))
In addition, you can do many similar mathematical operations, such as the following
The copy code is as follows:
Eval ('0'+new Array (11). Join (' + Math.pow (+ + iMagne2)') / / calculate the sum of squares from 1 to 10
Eval ('0'+new Array (100 impulse 2). Join (' + (iTunes 2)') / / calculates the sum of 2'4'6'.. 100
These calculations, which we used to do through loops, can now be cleverly done with one line of code, and we have to marvel at the hidden dexterity of the programming language. there are always too many things waiting for us to discover in the programming world.
Change the above JavaScript code to VBS, which is the so-called ashes solution of the VBS exercise:
The copy code is as follows:
Dim a (101)
Execute (Join (a, "s=s+i:i=i+1:"))
MsgBox s
Thank you for reading! This is the end of this article on "how to use vbscript to calculate the sum of 1 to 100". 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.