Page
  1. 1
    1
  2. 2
    2
  3. 3
    3
  4. 4
    4
  5. 5
    5
  6. 6
    6
  7. 7
    7

Selection Control and Repetition Control Structure

Extracts from this essay...

Introduction

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).

Middle

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.

Conclusion

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

The above preview is unformatted text

Found what you're looking for?

  • Start learning 29% faster today
  • Over 150,000 essays available
  • Just £6.99 a month

Not the one? Search for your essay title...
  • Over 180,000 student essays
  • Every subject and level covered
  • Thousands of essays marked by teachers
  • Over 180,000 essays
    written by students
  • Annotated by
    experienced teachers
  • Ideas and feedback to write
    your own great essays

Marked by a teacher

This essay has been marked by one of our great teachers. You can read the full teachers notes when you download the essay.

Peer reviewed

This essay has been reviewed by one of our specialist student essay reviewing squad. Read the full review on the essay page.

Peer reviewed

This essay has been reviewed by one of our specialist student essay reviewing squad. Read the full review under the essay preview on this page.