Selection Constructs

Selection Constructs

It is also known as conditional construct. It is used to indicate decision in a program. There are different kinds of selection constructs. They are

  • IF …THEN ….
  • IF THEN … ELSE ..
  • IF … THEN … ELSEIF….
  • MULTIPLE SELECTION

1. IF ....THEN CONSTRUCT :

This structure is also called as the ‘one-way branch ‘ decision structure.

IF test-condition then

Statement 2

Endif

In some situations, certain statements have to be executed only if a certain condition is met. In such cases, a test condition is specified. The test-condition is a Boolean expression which when tested results in TRUE or FALSE. When the condition is TRUE, statement enclosed between THEN and ENDIF are executed. If the condition is false, the statements are ignored and control is transferred to the statement following the if..then structure.

Example : Draw a flowchart to print the absolute value of an integer

Selection Constructs 7 

True

False

2. If ..Then ….Else Construct

This structure is also called as the ‘two-way branch” decision structure

If test-condition then

Statement 1

Else

Statement 2

Endif

If test-condition results in TRUE value, statement 1 is executed. If it is FALSE, statement 2 is executed. Statement 1 , Statement 2 can either be a single statement or a set of simple statements.

Example :Draw a flowchart to find the largest of two numbers

Selection Constructs 1


Last modified: Tuesday, 8 November 2011, 6:24 AM