A procedural program is a sequence of instructions for a computer to execute. Each instruction tells the computer what to do. It also might include a jump (go to) or loop that changes the sequence. Unlike conventional programs, Analytica models are (mostly) non-procedural — the model is a set of variables in no particular sequence, each with its own definition that expresses how to calculate its value. Each definition is usually a simple expression with functions, operators, constants, and other variables, but no procedural constructs controlling the sequence of execution. In this way, Analytica is like a standard spreadsheet application, in which each cell contains a simple formula with no procedural constructs. Analytica selects the sequence in which to evaluate variables based on the dependencies among them. Controlling the evaluation sequence via conditional statements and loops is a large part of programming in a language like in Fortran, Visual Basic, or C++. Analytica frees you from having to worry about sequencing. Non-procedural models or programs, like Analytica are usually much easier to write and understand than procedural programs. That's because you can understand each definition (or formula) without worrying about the sequence of execution.
However, procedural languages enable you to write more powerful functions that are hard or impossible without their procedural constructs. For this reason, Analytica offers a set of programming constructs, described in this chapter, providing a general procedural programming language for those who need it.
You can use these constructs to control the flow of execution only within the definition of a variable or function. Evaluating one variable or function cannot (usually) change the value of another variables or functions. Thus, these procedural constructs do not affect the simple non-procedural relationship among variables and functions. The only exception is that a function called from an event handler such as OnChange or a button OnClick attribute can change the definition of a global variable (see Button creation for more details).
- Procedural Programming Example
- Summary of Programming Constructs
- Begin-End for Grouping Expressions
- Local Values
- For and While Loops
- Local Indexes
- Ensuring Array Abstraction
- References and Data Structures
- Handles to Objects
- Dialog Functions
- Other Procedural Functions