Monday, August 26, 2013

Program control structures


Program control structures

  • During the early days of program development, the programmers developed large programs with logics of processing operations. 
  • Understandings the logic of such programs was very difficult for someone other than the developers. 
  • Hence, these programs were very difficult to modify for incorporating suggested enhancement and became very difficult for maintenance. 
  • Such problem was soon identified and the designers were contemplating into what factors contributed to unnecessary program complexity and how to develop program logics that are easier to comprehend resulting in easier maintenance of the corresponding program. 
  • Therefore , the designer could be expressed by using only the following three simple structures 
1. Sequence control structure
2. Selection control structure

3. Iteration control structure (Looping)
1.  Sequence control structure
  • The sequence logic is used for performing instructions one after another. 
  • Thus the pseudo code instructions of sequence logic are written in an order in which they are to be performed. 
  • This is denoted by writing one instruction or action one after another each instruction as a line by itself. 
  • The logic flow of pseudo code is top to bottom approach.





2. Selection control structure (or) Decision structure:
  • The selection logic is used for making decisions and also known as decision logic. 
  • It is used for selecting the suitable parts, out of two or more parts in the logic of the program. 
  • It is usually depicted as an IF. . . THEN or IF. . . THEN….ELSE or a CASE structure 
  • The IF…THEN structure specifies that, if the condition is true, then it carries out the process and if it is false then it skip over the process.

 
      
  • The IF …THEN..ELSE structure specifies that, if the condition is true, then it executes process 1 else i.e., condition is false executes process 2. 
  • In this case either process 1 or process 2 will only be executed depending on the condition

  •  The CASE structure is a multiway selection logic structure that is used to choose one option from two or more options in the program logic. 
  • It specifies that if the value of type is equal to Type-1 then execute process-1, if it is equal to Type-2 then execute process-2, if it is equal to Type-3 then execute process-3 and so. on. 
  • ENDCASE is used to indicate the end of the CASE structure.

 3. Iteration control structure (Looping):
  • This logic is used for producing loops in a programs logic, when one or more instruction may be executed several times or depending on some condition. 
  • It uses two structures called the WHILE and the DO – WHILE, both of these structures are used for looping 
  • The looping continues until the condition becomes True 
  • In case of while loop, the condition for looping is checked at the beginning of the loop 
  • If the condition is false, then the loop will not be executed, otherwise the loop is executed.  IT IS THE TOP TESTED LOOP
  •  In case of DO …WHILE loop, the condition for the loop is checked at the bottom, hence the body of the loop is executed at least once irrespective of the loop, i.e., it is the bottom tested loop.

No comments:

Post a Comment