| 1 | <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Verwendung von Variablen</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot"><link rel="home" href="index.html" title="Genius-Handbuch"><link rel="up" href="ch05.html" title="Chapter 5. GEL-Grundlagen"><link rel="prev" href="ch05.html" title="Chapter 5. GEL-Grundlagen"><link rel="next" href="ch05s03.html" title="Verwendung von Funktionen"></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">Verwendung von Variablen</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="ch05.html">Prev</a> </td><th width="60%" align="center">Chapter 5. GEL-Grundlagen</th><td width="20%" align="right"> <a accesskey="n" href="ch05s03.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-variables"></a>Verwendung von Variablen</h2></div></div></div><p lang="en"> |
| 2 | Syntax: |
| 3 | </p><pre lang="en" class="programlisting">VariableName |
| 4 | </pre><p lang="en"> |
| 5 | Example: |
| 6 | </p><pre lang="en" class="screen"><code class="prompt">genius> </code><strong class="userinput"><code>e</code></strong> |
| 7 | = 2.71828182846 |
| 8 | </pre><p lang="en"> |
| 9 | </p><p lang="en"> |
| 10 | To evaluate a variable by itself, just enter the name of the variable. This will return the value of the variable. You can use a variable anywhere you would normally use a number or string. In addition, variables are necessary when defining functions that take arguments (see <a class="xref" href="ch05s03.html#genius-gel-functions-defining" title="Definieren von Funktionen">the section called “Definieren von Funktionen”</a>). |
| 11 | </p><div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Vervollständigung mit der Tabulatortaste</h3><p lang="en"> |
| 12 | You can use Tab completion to get Genius to complete variable names for you. Try typing the first few letters of the name and pressing <strong class="userinput"><code>Tab</code></strong>. |
| 13 | </p></div><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Groß-/Kleinschreibung für Variablennamen</h3><p>Bei Variablennamen wird zwischen Groß- und Kleinschreibung unterschieden. Das bedeutet, dass die Variablennamen <code class="varname">hello</code>, <code class="varname">HELLO</code> und <code class="varname">Hello</code> als unterschiedliche Variablen erkannt werden.</p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-variables-setting"></a>Setzen von Variablen</h3></div></div></div><p lang="en"> |
| 14 | Syntax: |
| 15 | </p><pre lang="en" class="programlisting"><identifier> = <value> |
| 16 | <identifier> := <value> |
| 17 | </pre><p lang="en"> |
| 18 | Example: |
| 19 | </p><pre lang="en" class="programlisting">x = 3 |
| 20 | x := 3 |
| 21 | </pre><p lang="en"> |
| 22 | </p><p lang="en"> |
| 23 | To assign a value to a variable, use the <code class="literal">=</code> or <code class="literal">:=</code> operators. These operators set the value of the variable and return the value you set, so you can do things like |
| 24 | </p><pre lang="en" class="programlisting">a = b = 5 |
| 25 | </pre><p lang="en"> |
| 26 | This will set <code class="varname">b</code> to 5 and then also set <code class="varname">a</code> to 5. |
| 27 | </p><p lang="en"> |
| 28 | The <code class="literal">=</code> and <code class="literal">:=</code> operators can both be used to set variables. The difference between them is that the <code class="literal">:=</code> operator always acts as an assignment operator, whereas the <code class="literal">=</code> operator may be interpreted as testing for equality when used in a context where a Boolean expression is expected. |
| 29 | </p><p lang="en"> |
| 30 | For more information about the scope of variables, that is when are what variables visible, see <a class="xref" href="ch06s05.html" title="Globale Variablen und Variablenbereiche">the section called “Globale Variablen und Variablenbereiche”</a>. |
| 31 | </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-variables-built-in"></a>Eingebaute Variablen</h3></div></div></div><p lang="en"> |
| 32 | GEL has a number of built-in ‘variables’, such as |
| 33 | <code class="varname">e</code>, <code class="varname">pi</code> or <code class="varname">GoldenRatio</code>. These are widely used constants with a preset value, and |
| 34 | they cannot be assigned new values. |
| 35 | There are a number of other built-in variables. |
| 36 | See <a class="xref" href="ch11s04.html" title="Konstanten">the section called “Konstanten”</a> for a full list. Note that <code class="varname">i</code> is not by default |
| 37 | the square root of negative one (the imaginary number), and is undefined to allow its use as a counter. If you wish to write the imaginary number you need to |
| 38 | use <strong class="userinput"><code>1i</code></strong>. |
| 39 | </p></div><div class="sect2"><div class="titlepage"><div><div><h3 class="title"><a name="genius-gel-previous-result"></a>Vorherige Ergebnisvariable</h3></div></div></div><p lang="en"> |
| 40 | The <code class="varname">Ans</code> and <code class="varname">ans</code> variables can be used to get the result of the last expression. For example, if you had performed some calculation, to add 389 to the result you could do: |
| 41 | </p><pre lang="en" class="programlisting">Ans+389 |
| 42 | </pre><p lang="en"> |
| 43 | </p></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ch05.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ch05.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ch05s03.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 5. GEL-Grundlagen </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Verwendung von Funktionen</td></tr></table></div></body></html> |