1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Sums and Products</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Genius Manual"><link rel="up" href="ch06.html" title="Chapter 6. Programming with GEL"><link rel="prev" href="ch06s02.html" title="Loops"><link rel="next" href="ch06s04.html" title="Comparison Operators"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Sums and Products</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s02.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Programming with GEL</th><td width="20%" align="right"> <a accesskey="n" href="ch06s04.html">Next</a></td></tr></table><hr></div><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="genius-gel-sums-products"></a>Sums and Products</h2></div></div></div><p>
Syntax:
</p><pre class="programlisting">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></pre><p>
If you substitute <code class="literal">for</code> with <code class="literal">sum</code> or <code class="literal">prod</code>, then you will get a sum or a product instead of a <code class="literal">for</code> loop. Instead of returning the last value, these will return the sum or the product of the values respectively.
</p><p>
If no body is executed (for example <strong class="userinput"><code>sum i=1 to 0 do ...</code></strong>) then <code class="literal">sum</code> returns 0 and <code class="literal">prod</code> returns 1 as is the standard convention.
</p><p>
For floating point numbers the same roundoff error protection is done as in the for loop.
See <a class="xref" href="ch06s02.html#genius-gel-loops-for" title="For Loops">the section called “For Loops”</a>.
</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch06s02.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch06.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch06s04.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Loops </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Comparison Operators</td></tr></table></div></body></html>
|