Branch

From Free Pascal wiki
Jump to navigationJump to search

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:

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 (in FreePascal also strings are legal).

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.

See also