Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

en:simulation:benutzerdefinierte_funktionen:definition_benutzerdefinierter_funktionen:anweisungen [2025/05/13 10:04] – angelegt deppe2en:simulation:benutzerdefinierte_funktionen:definition_benutzerdefinierter_funktionen:anweisungen [2025/05/27 13:45] (aktuell) deppe2
Zeile 1: Zeile 1:
 ====== Statements ====== ====== Statements ======
 +
 +===== Statements =====
 +
 +The above described expression (mathematic and logical) is an inherent part of statements and cannot be used on their own. The user defined functions distinguish between four different statements. Each statement covers only a single line in the language.
 +
 +==== Assignments ====
 +
 +An assignment binds the value of a mathematical expression to a variable. Therefore, on the left hand side of the assignment sign (=) is the variable and on the right hand side a mathematical expression. The syntax is as follows:
 +
 +''<Identifier> `=´ <mathematical expression>''
 +
 +By using an assignment with an unknown identifier, a variable is created and initialized with the value of the given mathematical expression. The variable can be used later in mathematical expression to retrieve their value.
 +
 +The identifier has always to start with a letter, but numerals may be contained in the variable identifier.
 +
 +The value of logical expression cannot be bound to variables!
 +
 +In the following a few examples to assignments:
 +
 +| $\pi = 3.1415$ | valid assignment |
 +| $ab2 = a^2 + 2ab + b^2$ | valid assignment |
 +| $soNicht = (a < 0)$ | invalid, $a$ logical value can not be bound to variables |
 +| $a = b = 0.0$ | invalid, only single assignments are allowed |
 +| $2Pi = 2 + \pi$ | invalid, the identifier needs to start with a letter |
 + 
 +
 +==== Return ====
 +
 +A return statement determines the return-value of the user defined function. The evaluation of the function stops and the function is exited with the given return-value. The syntax is as follows:
 +
 +''`return´ <mathematical expression>''
 +
 +=== Conditional Statement ===
 +
 +An ''if-then-else'' statement evaluates a statement dependent on a given condition. This condition is expressed as a logical expression following the keyword if. If the condition holds, the statement following the then-keyword is evaluated, and otherwise the else denoted statement. The else-case is optional. If no else is given, simply the then denoted statement is not evaluated. The syntax is as follows:
 +
 +''`if´ <logical expression> `then´ <statement> [ `else´ <statement> ]''
 +
 +As a simple example the determination of the maximum of two values is shown below:
 +
 +<code>
 +if a < b        # Wenn a kleiner als b ist
 +then           # Dann
 +  max= b       # Ist b das Maximum
 +else           # Sonst
 +  max= a       # Ist a das Maximum
 +</code>
 +
 +
 +==== Grouping Statements ====
 +
 +The keywords begin and end parenthesize a sequence of statements. This group of statements can be evaluated as a single statement, for example in a conditional statement, where one of cases needs more than one single statement to work properly. The syntax is as follows:
 +
 +''`begin´''
 +
 +              <statement 1>
 +
 +                 ...
 +
 +              <statement n>
 +
 +`end´''