Difference between revisions of "Begin-End for Grouping Expressions"
Jhernandez3 (talk | contribs) (Created page with "Category: Analytica User Guide <breadcrumbs> Analytica User Guide > {{PAGENAME}}</breadcrumbs><br /> <footer>Summary of Programming Constructs / {{PAGENAME}} / Local Va...") |
Jhernandez3 (talk | contribs) m |
||
Line 2: | Line 2: | ||
<breadcrumbs> Analytica User Guide > {{PAGENAME}}</breadcrumbs><br /> | <breadcrumbs> Analytica User Guide > {{PAGENAME}}</breadcrumbs><br /> | ||
+ | As illustrated above, you can group several expressions (statements) as the definition of a variable or function simply by separating them by semicolons (;). To group several expressions as a condition or action of <code>If a Then b Else c</code> or <code>While a Do b</code>, or, indeed, anywhere a single expression | ||
+ | is valid, you should enclose the expressions between '''<code>Begin</code>''' and '''<code>End</code>''', or between parentheses characters ( and ). | ||
+ | The overall value of the group of statements is the value from evaluating the last expression. For example: | ||
+ | |||
+ | <code>(VAR x := 10; x := x/2; x - 2) → 3</code> | ||
+ | |||
+ | Analytica also tolerates a semicolon (<code>;</code>) after the last expression in a group. It still returns the value of the last expression. For example: | ||
+ | |||
+ | <code>(VAR x := 10; x := x/2; x/2;) → 2.5</code> | ||
+ | |||
+ | The statements can be grouped on one line, or over several lines. In fact, Analytica does not care where new-lines, spaces, or tabs occur within an expression or sequence of expressions — as long as they are not within a number or identifier.<br /> | ||
<footer>Summary of Programming Constructs / {{PAGENAME}} / Local Variables</footer> | <footer>Summary of Programming Constructs / {{PAGENAME}} / Local Variables</footer> |
Revision as of 13:38, 15 December 2015
As illustrated above, you can group several expressions (statements) as the definition of a variable or function simply by separating them by semicolons (;). To group several expressions as a condition or action of If a Then b Else c
or While a Do b
, or, indeed, anywhere a single expression
is valid, you should enclose the expressions between Begin
and End
, or between parentheses characters ( and ).
The overall value of the group of statements is the value from evaluating the last expression. For example:
(VAR x := 10; x := x/2; x - 2) → 3
Analytica also tolerates a semicolon (;
) after the last expression in a group. It still returns the value of the last expression. For example:
(VAR x := 10; x := x/2; x/2;) → 2.5
The statements can be grouped on one line, or over several lines. In fact, Analytica does not care where new-lines, spaces, or tabs occur within an expression or sequence of expressions — as long as they are not within a number or identifier.
Enable comment auto-refresher