Iteration
Iteration is the ability to control how many times a statement will be executed.
Iteration is the ability to control how many times a statement will be executed. Iterative statements are composed of a head and a body. The body is composed of statements that will be executed. The head controls the number of times that the body will be executed. There are three basic types of iterative statements and all of them follow the basic structure seen below.
The first type of iterative statement is the simple repetition. In this structure, the head simply indicates how many times the body will be executed. A simple repetition iterative statement takes on the following form in most programming languages. “Perform body X times.” You can try doing a fixed iteration with the Visual Basic Editor. Below is an example of a fixed iteration.
The second type of iterative statement is repetition while a condition holds. In this structure, the head instructs the body to execute while a condition is satisfied. After the body has been executed, the head executes the body again if the conditions are still satisfied. Otherwise, the program stops. The body is expected to modify values in the conditions so that at some point, the program will stop.
A good example of an iterative statement program with conditions is the counter controlled program. The head has a variable that serves as a counter. Whenever the body is executed, the variable is incremented. The program will stop when the variable reaches the limit specified in the head. You can use your Visual Basic Editor to type in a iterative program that has conditional properties. Below is an example of such procedure.
The third type of iterative statement is indefinite repetition. In this structure, the head instructs the body to execute over and over again without specifying a termination point. Exiting the procedure is done manually. You can use your Visual Basic Editor to type in an indefinitely iterating program. Below is an example of an indefinite iteration. Note that the variable "People" is now set as data type "Long" instead of data type "Integer." The "Long" data type is capable of numbers up to 2 billion while the "Integer" data type is only capable of numbers up to 32,767. If you want to exit the indefinite iteration, simply press the Escape button.