File: ch06s03.html

package info (click to toggle)
genius 1.0.27-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 25,308 kB
  • sloc: ansic: 75,620; xml: 71,565; sh: 4,445; makefile: 1,927; lex: 523; yacc: 298; perl: 54
file content (11 lines) | stat: -rw-r--r-- 2,973 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Summor och produkter</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Handbok för Genius"><link rel="up" href="ch06.html" title="Chapter 6. Programmering med GEL"><link rel="prev" href="ch06s02.html" title="Slingor"><link rel="next" href="ch06s04.html" title="Jämförelseoperatorer"></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">Summor och produkter</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch06s02.html">Prev</a> </td><th width="60%" align="center">Chapter 6. Programmering med 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>Summor och produkter</h2></div></div></div><p lang="en">
Syntax:
</p><pre lang="en" class="programlisting">sum &lt;identifier&gt; = &lt;from&gt; to &lt;to&gt; do &lt;body&gt;
sum &lt;identifier&gt; = &lt;from&gt; to &lt;to&gt; by &lt;increment&gt; do &lt;body&gt;
sum &lt;identifier&gt; in &lt;matrix&gt; do &lt;body&gt;
prod &lt;identifier&gt; = &lt;from&gt; to &lt;to&gt; do &lt;body&gt;
prod &lt;identifier&gt; = &lt;from&gt; to &lt;to&gt; by &lt;increment&gt; do &lt;body&gt;
prod &lt;identifier&gt; in &lt;matrix&gt; do &lt;body&gt;</pre><p lang="en">

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>Om ingen kropp exekveras (till exempel <strong class="userinput"><code>sum i=1 to 0 do ...</code></strong>) så kommer <code class="literal">sum</code> att returnera 0 och <code class="literal">prod</code> att returnera 1 som är standardkonventionen.</p><p>För flyttal görs samma skydd mot avrundningsfel som i for-slingan. Se <a class="xref" href="ch06s02.html#genius-gel-loops-for" title="For-slingor">the section called “For-slingor”</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">Slingor </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Jämförelseoperatorer</td></tr></table></div></body></html>