In many instances of repetition, we know ahead of time
how many of those we must perform. So the program can either fix the number
of cycles or it can prompt the user for the number of cycles and then proceed
accordingly. These types of loops are called counting loops. For example
if we want to list the grades of students in a class, we may first ask the
user for the size of the class and then loop through the grades and list
them. Or, if we need to create a table with 16 lines, again we can
loop 16 times and create the table. The following is an annotated example for a typical problem in engineering . We want to place a given number of points in between two fixed points, and do so while we keep the distances between all points equal. |
Read the purpose and algorithm of the example for more information on this important topic:
© 2001 J.Y. Kazakia. All rights reserved