OpenMusic

Visual Programming | Computer-Assisted Composition

Navigation : Previous Next

Sum : Calculating Sums

Sum adds the successive input values.

Inputs, Outputs

Sum has one input and three outputs :

  1. triggers the collection of a new value, and the addition of this value to a sum

  2. returns the current value of the sum

Examples

Calculating a Sum from a List

The components of a list are returned successively by listloop to sum.

  1. At each step of the loop, eachtime triggers and prints the sum of the components.

  2. The state of sum at the end of the loop, that is, the sum of all the components of the list, is returned by finally.

Calculating the Sum of N Random Numbers

We now want to calculate the sum of 10 random numbers between 1 and 10.

  1. The number of loops is defined by forloop.

  2. At each step :

* a random number is returned by **om-random** and printed
* the sum of the successive is returned by **sum** and printed.   3. After ten loops, the iteration is stopped by **forloop**.
  1. Finally returns the sum of the whole set of numbers returned by om-random.

Contents :

Navigation : Previous Next