Difference between revisions of "Branch"
(create) |
m (→Usage: insert link to Case Compiler Optimization) |
||
Line 20: | Line 20: | ||
== Usage == | == Usage == | ||
− | <syntaxhighlight lang="pascal" inline>Case … of</syntaxhighlight> branches should be considered where appropriate since they aide compiler optimizations. | + | <syntaxhighlight lang="pascal" inline>Case … of</syntaxhighlight> branches should be considered where appropriate since they [[Case Compiler Optimization|aide compiler optimizations]]. |
By using them [[FPC]] may re-arrange statements, the given alternatives, in order to optimize for speed or size. | By using them [[FPC]] may re-arrange statements, the given alternatives, in order to optimize for speed or size. |
Revision as of 08:43, 22 June 2020
│
Deutsch (de) │
English (en) │
A branch, also called conditional or conditional statement, is a statement that is executed depending on an expression’s value. Usually this expression depends on the program’s state.
Types of branches
Pascal knows two types of branches:
if … then …
conditional statements, andcase … of …
statements.
They differ in how many alternatives can be named, how many “routes” could be taken.
In an if … then …
branch there exists exactly one alternative.
It is either executed or not.
In conjunction with the word else
one can specify exactly two “paths” with regard to program flow.
Due to its binary nature, if … then
requires a Boolean expression to be evaluated.
Case … of
on the other hand is n-ary, where n is greater than one.
Unlike if
the supplied expression the program flow depends on can (and has to) be of any integral type, e. g. an integer or enumeration.
Usage
Case … of
branches should be considered where appropriate since they aide compiler optimizations.
By using them FPC may re-arrange statements, the given alternatives, in order to optimize for speed or size.