Sign in Join
Wiki copytemporary

Branch: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Branch

OldNewLine
1+A **branch**, also called **conditional** or **conditional statement**, is a [[statement]] that is executed depending on an [[expression|expression’s]] value. Usually this expression depends on the [[Program|program’s]] state.
2+
3+## Types of branches
4+
5+[[Pascal]] knows two types of branches:
6+
7+- [[If and Then|if … then …]] conditional statements, and
8+- [[Case|case … of …]] statements.
9+
10+They differ in how many alternatives can be named, how many “routes” could be taken.
11+
12+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 Expressions|Boolean expression]] to be evaluated.
13+
14+`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|integer]] or [[Enum Type|enumeration]] (in FreePascal also [[String|strings]] are legal).
15+
16+## Usage
17+
18+`Case … of` 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.
19+
20+## See also
21+
22+- [[Conditional compilation|conditional compilation]] and related compiler directives do *not* create branches
23+
24+---
25+*From the Free Pascal wiki, page "Branch", as it stood on 2020-06-23 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history