Chapter 4 - Repetition Structures
Chapter 4: Repetition Structures
This chapter shows the student how to create repetition structures using the loop and loop. Counters, accumulators, running totals, and sentinels are discussed, as well as techniques for writing input validation loops.
Chapter 4 Learning Outcomes
Upon completion of this week's material, you should be able to:
- describe the while loop A Condition controlled loop.
- describe the for loop: A counter-controlled loop.
- list and describe the four major components of a pre-test loop in a computer program;
- describe the difference between a count-controlled loop and a sentinel loop, and the three pieces of information needed for the counter in a count-controlled loop;
- Create Python code that includes post-test loops, count-controlled loops, sentinel loops, and nested loops using the while and for statements appropriately.
- describe input validation loops.
Highlights This Week
In chapter 3 we examined the logical structure of algorithms and focused on implementing conditional branch execution in Python code. In Phyton this centered on three programming statements. (If / if-else, /if-elif-else).
Additionally, the chapter began to look at relational operations that compared values to yield true or false results. These relational operations are referred to as logical expressions. Logical expressions use comparative operators to compare the values of data in computer memory. finally, the chapter examined logical operations that combine values in Boolean expressions to form more complex expressions. The logical operators that were discussed were the (and, or, not) logical operators. This overall examined the nature of algorithms and their structure.
In Chapter 4, we examine another significant component of the logical structure of an algorithm in a computer program, the repetition sequence. In computer science and Computer Technology, the repetition sequence is also referred to as a loop. Loops provide the means of repeating a sequence of computer instructions multiple times.
Chapter 4 describes the fundamental components of a looping structure. It is very important to understand the fundamental components of a looping structure. Later, this understanding will provide a means to better troubleshoot logical problems in your repetition sequences.
The Fundamental components of Repetition Sequences are the Initialization process, the Testing process, the Updating process, and the Process that is being performed repetitively.
In the case of the pre-test loop, the loop control variable has to set to a value that permits the loop to be entered and executed. Just as in the selection sequences a looping sequence can have multiple logical expressions to determine the overall outcome of a complex logical expression. Just as with selection sequences, the logical operators (and, or, not) are used to join multiple logical expressions together to form a complex logical expression.
The chapter attempts to describe the differences between sentinel control variables and count control variables.
In Python, the while-loop is typically used to create a pre-test looping sequence. A special type of looping structure discussed for-loop; this type of loop combines the Initialization process, the Testing process, the Updating process in the looping structure heading area.
Please continue to the next page.