Repetition/Looping Structures

 

Another collection of the most fundamental structures has to do with repeating operations.  This is  done in two fundamentally different ways, incrementing a counter and evaluating a criteria.  Obviously you could use a criteria that makes use of counting so the approaches aren't mutually exclusive.  It is also possible to evaluate the criteria either at the beginning or the end of the loop.

For example, you want to loop through and consider the grades of all the students in a class.  You may be computing each person's overall class average.  

There are endless examples of such situations. 

The following three diagrams represent the three fundamental repetition/looping structures.

The first one is the basic While  structure.  For example, if someone has a grade above a particular level then they should get an A.

 

 

The next structure relates to having evaluating the condition at the end of the loop.  This is enacted with a do - while loop in Java.

 

 

Finally, we have highly structured situations where the number of repetitions through the loop is largely foreknowledge.  This is equivalent to a  for  loop in Java.