Skip to main content

Selection

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 dependant 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 an If statement:

 
If (Condition)
Then
{ Program Statements }
 


OR

 
If (Condition)
Then
{ 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 being true or false.

Next: Logical Operators