Trace:

array_20arithmetic

This shows you the differences between two versions of the page.

array_20arithmetic [2018/03/31 13:19] 127.0.0.1 external edit |
array_20arithmetic [2018/04/17 15:08] (current) tbest3112 Added syntax highlighting |
||
---|---|---|---|

Line 2: | Line 2: | ||

//by Richard Russell, March 2014//\\ \\ **LB Booster** supports the ability to perform arithmetic operations on whole arrays, that is the operation is performed individually on every element of the array without you having to code a loop. For example you can add, subtract, multiply or divide arrays as follows:\\ | //by Richard Russell, March 2014//\\ \\ **LB Booster** supports the ability to perform arithmetic operations on whole arrays, that is the operation is performed individually on every element of the array without you having to code a loop. For example you can add, subtract, multiply or divide arrays as follows:\\ | ||

+ | <code lb> | ||

a() = b() + c() | a() = b() + c() | ||

a() = b() - c() | a() = b() - c() | ||

a() = b() * c() | a() = b() * c() | ||

a() = b() / c() | a() = b() / c() | ||

+ | </code> | ||

Note that the arrays must all be the same size. If each array has a maximum index value of 10 (the default) the first of the above examples is equivalent to (but will run much faster than) this code:\\ | Note that the arrays must all be the same size. If each array has a maximum index value of 10 (the default) the first of the above examples is equivalent to (but will run much faster than) this code:\\ | ||

+ | <code lb> | ||

for i = 0 to 10 | for i = 0 to 10 | ||

a(i) = b(i) + c(i) | a(i) = b(i) + c(i) | ||

next i | next i | ||

+ | </code> | ||

You can also add, subtract, multiply or divide each element by a scalar numeric value as follows:\\ | You can also add, subtract, multiply or divide each element by a scalar numeric value as follows:\\ | ||

+ | <code lb> | ||

a() = b() + n | a() = b() + n | ||

a() = b() - n | a() = b() - n | ||

a() = b() * n | a() = b() * n | ||

a() = b() / n | a() = b() / n | ||

+ | </code> | ||

The + (concatenation) operator can be used with string arrays:\\ | The + (concatenation) operator can be used with string arrays:\\ | ||

+ | <code lb> | ||

a$() = b$() + c$() | a$() = b$() + c$() | ||

a$() = b$() + "!" | a$() = b$() + "!" | ||

+ | </code> | ||

Finally, you can assign the same value to every element of an array in one operation:\\ | Finally, you can assign the same value to every element of an array in one operation:\\ | ||

+ | <code lb> | ||

a() = 4 * atn(1) | a() = 4 * atn(1) | ||

a$() = "Hello world!" | a$() = "Hello world!" | ||

+ | </code> |

array_20arithmetic.1522502345.txt.gz ยท Last modified: 2018/03/31 13:19 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International