# Simple math and Arrays

## Recommended Posts

I was just wondering how do you do math using arrays?

For example:

\$array[1]= 10

\$array[2] = 20

\$array[3] = 30

\$array[4] = 40

\$array[5] = 50

How would i "add" them together without doing this, \$array[1] + \$array[2] + \$array[3] etc.

If we use a For loop, how would the adding part look?

```For \$x = 1 To UBound(\$array)
\$sum = \$array[\$x] ?
?
Next```

Thats pretty much what i got atm...

"I'm paper, rock is fine, nerf scissors!!!"

##### Share on other sites

I was just wondering how do you do math using arrays?

For example:

How would i "add" them together without doing this, \$array[1] + \$array[2] + \$array[3] etc.

If we use a For loop, how would the adding part look?

```For \$x = 1 To UBound(\$array)
\$sum = \$array[\$x]
?
Next```

Thats pretty much what i got atm...

```For \$x = 1 To UBound(\$array) - 1
\$sum = \$sum + \$array[\$x]
Next```
Edited by gafrost

Don't argue with an idiot; people watching may not be able to tell the difference.

##### Share on other sites

```Dim \$i, \$sum, \$array[5]
\$array[0] = 1
\$array[1] = 2
\$array[2] = 3
\$array[3] = 4
\$array[4] = 5
\$sum = 0
For \$i = 0 to ubound(\$array, 1) - 1
\$sum = \$sum + \$array[\$i]
Next
msgbox(0,'',\$sum)```

That 'ought to work, havent tested it.

~cdkid

**edit**

gar, too slow

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

##### Share on other sites

Thanks alot guys

"I'm paper, rock is fine, nerf scissors!!!"

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...