Selection Control and Repetition Control Structure
Extracts from this document...
Selection Control and Repetition Control Structure University of Phoenix Mayada Set PRG/210 Fundamental of Programming with Algorithm and Logics Instructor Name: Guillermo A. Hernandez Date: May 15, 2009 Before writing a program to solve a problem, we must have a thorough understanding of the problem and a carefully planned approach to solving it. When writing a program, we must also understand the types of building blocks that are available and employ proven program construction techniques. A computer can process a program in one of three ways: in sequence; selectively by making a choice, which is also called a branch; or repetitively by executing a statement over and over, using a structure called a loop. Control structures provide alternatives to sequential program execution and are used to alter the sequential flow of execution. The two most common control structures are selection and repetition. In selection, the program executes particular statements depending on some condition(s). In repetition, the program repeats particular statements a certain number of times depending on some condition(s). ...read more.
When neither condition is true, then the combined condition is considered false. - Nested selection is used for multiple cases by placing if.......else selection statements inside other if.........else selection statement. For example: If student_grade >= 90 then Print "A" Else If student_grade >= 80 then Print "B" Else If student_grade >= 70 then Print "C" Else If student_grade >= 60 then Print "D" Else Print "F" Endif Endif Endif Endif Note that there are an equal number of IF, ELSE and ENDIF statements, that each ELSE and ENDIF statement is positioned so that it corresponds with its matching IF statement, and that the correct indentation makes it easy to read and understand. The other type of structure control is repetition control. The repetition structure is a bit more complicated than the selection structure, but it is easy to understand. A repetition structure consists of a block of statements that are executed repetitively. They might be executed once or a hundred times depending on the controls placed on the structure. ...read more.
If the condition is false, the statements will be repeated UNTIL the condition becomes true. The format of the REPEAT...UNTIL structure is: REPEAT statement statement . . UNTIL condition is true Counted repetition occurs when the exact number of loop iterations is known in advance. The execution of the loop is controlled by a loop index, and instead of using DOWHILE, or REPEAT...UNTIL, the simple keyword DO is used as follows: DO loop_index = initial_value to final_value statement block ENDDO The DO loop does more than just repeat the statement block. It will: 1. initialize the loop_index to the required initial_value 2. increment the loop_index by 1 for each pass through the loop 3. test the value of loop_index at the beginning of each loop to ensure that it is within the stated range of values 4. terminate the loop when the loop_index has exceeded the specified final_value. . Reference: 1. Simple Program Design: A Step by Step Approach, Chapter 4, 5e by Lesley Anne Robertson. 2. Simple Program Design: A Step by Step Approach, Chapter 5, 5e by Lesley Anne Robertson ?? ?? ?? ?? Selection and Repetition Control Structure 1 ...read more.
This student written piece of work is one of many that can be found in our University Degree Engineering section.
Found what you're looking for?
- Start learning 29% faster today
- 150,000+ documents available
- Just £6.99 a month
- Join over 1.2 million students every month
- Accelerate your learning by 29%
- Unlimited access from just £6.99 per month