Repetition control structure is also known as looping or iteration control structure. .Repetition is the act of repeating steps in a certain process. It consists of a branching backwards away from the normal sequence of steps towards an earlier step. The branching decision is based on a relationship between the values of known data (condition) at the time that the branching test is performed. The condition is usually based on the value of a single variable (control variable). The steps to be repeated are referred to as the loop body. Each execution of the steps is referred to as a pass or iteration. The step where the body starts is called as the loop entrance and the step where the test branches back fails is known as the loop exit, it causes the repetition to stop.
It is a process of executing one or more steps of an algorithm or program repeatedly. Repetition is needed to add a list of numbers or variables for each number and one for the total would need to be declared. For a different number of values, recoding would be required. C++ has three repetition structures that repeat statements over and over until certain conditions are met. Repetition control system is very essential in programming for most programs do repetitious tasks.
2. What are the different types of repetition control structure?
The two basic types of loops are pre-test loop and the post-test loop.
PRE-TEST LOOP The pre-test loop can be put to in VB with a "Do" statement followed by either the keyword "While" or "Until". "Do While" means execute the statements entered in the body of the loop While a certain condition is true. "Do Until" means execute the statements in the body of the loop until a certain condition is true. While and Until are opposite to each other, doing something Until a condition is TRUE is the same as doing something While a condition is FALSE. Do While X 10. In C++, while is a reserved word. The expression acts as a decision maker. It is called the loop condition. The statement can be either a simple or compound statement. It is called the body of the loop.
[pic]
The While/Wend Loop- it is an older statement pair from previous versions of BASIC and was included in VB for compatibility. The format is:
While Wend The following two code segments produce the exact same results: |intNum = Val(InputBox("Enter a number")) |intNum = Val(InputBox("Enter a number")) |
|Do While intNum > 0 |While intNum > 0 |
| intNumSq = intNum ^ 2 | intNumSq = intNum ^ 2 |
|Print intNum; "squared is"; intNumSq | Print intNum; "squared is"; intNumSq |
| intNum = Val(InputBox("Enter a number")) | intNum = Val(InputBox("Enter a number")) |
|Loop |Wend |
There is no "Until" equivalent of "While/Wend"
The For/Next Loop – it uses a built-in counting procedure to repeat a series of instructions a specific number of times. Let us compare counting with Do/Loop vs. counting with For/Next. With Do While, you could set up a loop to print the numbers from 1 to 5 as follows:
intCounter = 1 Do While intCounter
You May Also Find These Documents Helpful
-
1. What does redundancy refer to? Redundancy refers to repeating the same data more than once; It occurs in a number of ways such as the data could be repeated over and over again in the same file.…
- 330 Words
- 1 Page
Satisfactory Essays -
1. A while loop will not execute the body of the code if you have your test condition incorrect.…
- 3740 Words
- 15 Pages
Satisfactory Essays -
5. What three actions do count-controlled loops typically perform using the counter variable? Initialization: Before the loop begins, the counter variable is initialized to a starting value. Test : The loop tests the counter variable by comparing it to a maximum value. If the counter variable is less than or equal to the maximum, the loop iterates. If the counter is greater than the maximum value, the program exits the loop. Increment : To increment a variable means to increase its value. During each iteration, the loop increments the counter variable by adding a predetermined amount to it…
- 431 Words
- 2 Pages
Satisfactory Essays -
DQ 1: Review the definition of control structure on p. 45 in Extended Prelude to Programming: Concepts and Design (2nd ed.). Then, think about the pseudocode algorithm you would write for a simple task (making a peanut butter sandwich, for example) as well as three simple control structures that could be used to create this algorithm.…
- 437 Words
- 2 Pages
Satisfactory Essays -
Olzak, T. (2010, July 5). The future of iris scanning. Retrieved November 2013, 2013, from A Tech Republic Website: http://www.techrepublic.com/blog/it-security/the-future-of-iris-scanning/…
- 1902 Words
- 8 Pages
Better Essays -
2. A pretest loop is a loop tests the conditions before performing the iteration. A posttest loop performs the iteration then test the condition.…
- 261 Words
- 2 Pages
Satisfactory Essays -
A worm is moving toward an apple. Each time it moves, the worm cuts the distance between itself and the apple by its own body length until the worm is close enough to enter the apple. The worm can enter the apple when it is within a body length of the apple.…
- 1775 Words
- 8 Pages
Powerful Essays -
A condition-controlled loop uses a true/false condition to control the number of times that it repeats…
- 1058 Words
- 5 Pages
Satisfactory Essays -
C++ programming: editing, compiling, user I/O, variables (ints, doubles, char, strings, booleans), loops, decisions, functions, pointers, arrays, tables, databases, sorting.…
- 1748 Words
- 8 Pages
Powerful Essays -
a repetition of n times. If you put {n,m} it means it repeats a minimum of ‘n’ and the maximum of ‘m’…
- 518 Words
- 4 Pages
Satisfactory Essays -
Closed loop control is a theory of motor control that involves an executive, comparator, and effector components. The steps in the closed loop schematic diagram starts off with the input (stimuli) which then goes through info processing. the info processing is the executive stage and within this stage there are three different process that occur. The first process is the Stimulus identification, which identifies what it is. Then after is the response selection and then follows the response programming. After comes the output which leads into the effectors, or muscle glands. Also coming from the output is the desired state which leads to the cerebellum. From the muscle glands there are two types of feedbacks. The two types of feedbacks are interceptive and exteroceptive. These both lead up to the cerebellum, also known as the comparator, the third component. The comparator receives info about the desired state and actual state and compares. After comparing it goes through motor error and then updates the stimulus identification.…
- 488 Words
- 2 Pages
Good Essays -
Traditional learning viewpoints considered classical and operant conditioning to be automatic processes involving only environmental events that did not depend at all on biological or cognitive factors. Research on which of the following concepts cast doubt on this point of view?…
- 2606 Words
- 20 Pages
Good Essays -
3. Open-loop motor control relies on sensory feedback to guide the completion of the movement.…
- 23222 Words
- 93 Pages
Powerful Essays -
5. What distinguishes a Loop control construct from a While control construct, in terms of what is known about the number of times the block of code will be repeated?…
- 610 Words
- 3 Pages
Good Essays -
a) Select two companies where inadequate internal control have resulted in disastrous effects on the organisation or exposed it to heavy losses.…
- 369 Words
- 3 Pages
Satisfactory Essays