Program Control Structuresprogram control structures are blocks of statements that determine how statements are to be executed, in structured programming languages, there are three control structures namely; sequence, selection and iteration (looping) SequenceIn this structure, the computer reads instructions from a program file starting from the first top line and proceeding downwards one -by -one to the end. This is called sequential programming execution i.e. SelectionIn selection control, execution of statements depends on a condition which is either a true or false There are four types of selection controls. Namely:
The IF....THEN selection is used if only one option is available. All other options are ignored Format: IF <condition> THEN Statements; ENDIF IF....THEN....ELSE This type of selection is suitable where there are two available options General Format IF <condition> THEN Statements; ELSE Statements; EndIF Nested IF Selection This type of selection is used where two or more options have to be considered to make a selection. General Format IF <condition> THEN statements ELSE IF <condition> THEN statements ELSE IF<condition> THEN Statements ELSE Statements ENDIF ENDIF ENDIF CASE Construct This is an alternative to the Nested IF especially where there are several options to choose from. Its preferred because it reduces the many lines of code. However, the boolean expression for the case selection can only be expressed using integers and alphabetic characters only. The General format should be CASE integer OF or CASE Char OF Example: Case x of label 1: statement 1 label 2: statement 2 label 3: statement 3 . . . label n: statement n-1 Else statement Endcase Iteration (looping)Iteration is also referred to as looping or repetition. Its designed to execute the same block of code again and again until a certain condition is fulfilled. The three main looping controls are:-
The "WHILE" loop is used if a condition has to be met before the statements within the loop are executed. General Format WHILE condition DO statement ENDWHILE The REPEAT....UNTIL loop The REPEAT....UNTIL loop allows the statements within it to be executed at least once since the condition is tested at the end of the loop. General Format REPEAT statements UNTIL <condition> The FOR Loop The FOR loop is used in circumstances where the execution of the chosen statements has to be repeated a predetermined number of times. General Format //pseudocode for 'FOR" loop that counts from the lower limit FOR loop variable = lower limit to upper limit DO statements ENDFOR Follow AtikaSchool.Org on our Social ChannelsThis gives you an opportunity to get our latest uodates, changes and firsthand information
0 Comments
Leave a Reply.Don't give up, Keep Searching for more |
Categories
All
Archives
January 2025
|