Procedural Programming
Analytica is mostly a declarative or non-procedural language. You create a model by creating variables, each with a definition expressing how to calculate it from other variables and functions (or just a number or distribution). Because it has no (global) assignments, you can understand each definition (or formula) on its own without worrying about what happened before or after. There is no required sequence to write or read the sequence of variables. Analytica figures out what sequence to evaluate them at runtime to maintain consistency and efficiency without you having to tell it. Plus Intelligent Arrays lets you work with single or multidimensional arrays without having to write for loops to iterate over each dimension. All this frees you, as a model builder or reader of someone else's model, from having to worry about the flow of control. That gives Analytica a huge advantage in clarity and reliability over most conventional computer languages that are procedural, like in Fortran, Visual Basic, C++, Javascript, and so on. Programming in such languages means spending a lot of effort designing (and then debugging) the flow of control using assignments, conditionals, and loops. That's why we say Analytica enables you to be a modeler without being a programmer.
However there are occasional situations where it's more convenient to express an algorithm in procedural form. For this reason, Analytica offers a set of programming constructs, described in this chapter, giving you a general procedural programming language for those who want or need it. But most modelers can blissfully just ignore it!
You can use these procedural constructs to control the flow of evaluation only within the definition of a variable or function. Evaluating one variable or function cannot (usually) change the value of another global variables or functions. In this way, they do not affect the simplicity and clarity of the declarative relationships among global variables and functions. (There are some minor exceptions, like assignments in the OnChange of a user input or OnClick attribute of a Button, and the ComputedBy function, but even these are carefully designed to maintain the simple declarative forms.)
Sections
- Procedural Programming Example
- Summary of Programming Constructs
- Begin-End for Grouping Expressions
- Local Values
- For and While Loops
- Recursion
- Local Indexes
- Ensuring Array Abstraction
- References and Data Structures
- Handles to Objects
- Dialog Functions
- Other Procedural Functions
See Also
Enable comment auto-refresher
Lchrisman