Jump to content

Conditional branch

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Endlessnameless (talk | contribs) at 22:04, 17 December 2004 (fix bad link). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A conditional branch is a basic logical structure. It resembles a fork in the road; there are several paths, and the operator must choose one of them.

This is a common method in computer programming. If a certain condition exists (e.g., the hard disk drive is in use), then the application will perform one action (in this case, it will wait), while if this condition does not exist the application will perform another action (read from or write to the hard disk).

Conditional statements can be assessed based on any number of data, including:

  • resource availability (semaphores, mutexes)
  • environmental characteristics (operating system, available APIs or libraries, other processes)
  • internal variables such as the result of a previous equation or the setting of a state flag

Conditional branches are often issued in speculative execution, primarily because there is no simple solution to predict which branch will be selected when the condition is evaluated. Branches where the results of the conditional statement affect the outcome of the branch's execution are particularly difficult because they cannot be executed speculatively at all in a strict programming language (C_programming_language C, C++, Java_programming_language Java, BASIC_programming_language BASIC, FORTRAN, and others) without substantial effort on the part of the programmer to allow for it. Since these languages form the bulk of existing commercial applications, the efficient use and executive optimization of branches is an important concern for many programmers working on applications, compilers, and CPU architectures.