Sign in Join
Wiki copytemporary

Branch

Deutsch · English

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


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.

Revision 1, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.