Sums and Products
Prev | Chapter 6. Programming with GEL | Next

## Sums and Products

Syntax:

    sum <identifier> = <from> to <to> do <body>
    sum <identifier> = <from> to <to> by <increment> do <body>
    sum <identifier> in <matrix> do <body>
    prod <identifier> = <from> to <to> do <body>
    prod <identifier> = <from> to <to> by <increment> do <body>
    prod <identifier> in <matrix> do <body>

If you substitute `for` with `sum` or `prod`, then you will get a sum or a product instead of a `for` loop. Instead of returning the last value, these will return the sum or the product of the values respectively.

If no body is executed (for example `sum i=1 to 0 do ...`) then `sum` returns 0 and `prod` returns 1 as is the standard convention.

For floating point numbers the same roundoff error protection is done as in the for loop. See the section called “For Loops”.

Prev | Up | Next
Loops | Home | Comparison Operators