Selection

Decision Making

The decision-making capability of a programming language is very simple. High-level language statements only have the ability to test to see if a condition is true or false.

Most programming problems involve alternate series of commands dependent upon the value of a condition. An algorithm will show the different execution paths. That is, a different set of instructions will be executed for each value of the condition. This program control construct is known as Selection.

The simplest selection is a binary selection where the condition will either be true or false. This is accomplished by using the if statement:

if (Condition)
{
Program Statements
}

OR

if (Condition)
{
Program Statements
}
else
{
Program Statements
}

Most conditions compare the value of two pieces of data that are of the same data type, with the result of the comparison either being true or false.

Next: Logical Operations