Introduction to Control Structures
There are three types of Control Structures:
Selection: The Selection construct, is a block of instructions, in which only a
few will be executed based on the results of controlling condition. For example, IF-THEN-ELSE
Sequence: This structure is the computer’s ability to perform instructions in a linear progression. For example, pseudocode.
Repitition: Repetition is the computer’s ability to perform a block of instruction until the loop controlling condition evaluates to false. The set of statements that gets repeated in a loop are called loop statements.
Types of Selection
IF-THEN: The instructions in the body of the IF-THEN are only performed when the condition evaluates to true. The action to be taken if the condition evaluates to false is not stated and by default the flow of the performance of the instructions moves along to ENDIF keyword and to the statements beyond the ENDIF.
Example: If (Grade>= 80) then
Print “Pass”
ENDIF
IF-THEN-ELSE: Performs an action if the condition is true and also performs
another action if the condition is false.
Example: (IF num 1 > num 2) then
Print “Bigger number is”, num 1
Else
Print ‘Bigger number is’, num 2
ENDIF
IF-THEN-ELSE-IF: First checks the "if" condition; if true, it executes that block and skips the rest. If false, it moves to the "else if" conditions in order, executing the first one that is true. If none of the "if" or "else if" conditions are true, it executes the final "else" block.