Iteration SCLM

Re-usable Code

     By using iteration most programs are said to run only in about 10% of the code 90% of the time.  This is due to the ability for code to be reused in a program.  When taking the sum of a set of numbers we might want to use the following piece of code iteratively:

...Pre-Conditions

Sum = Sum + Next_Number;  //This step adds the following number to Sum

...Post-Conditions

As we can see that step is crucial when finding the sum, therefore by iterating that same line of code we've allowed the code to be repeated.  Though we assume as a Pre-Condition that the next number in the set will be Next_Number.


PreviousNext

Previous Table of Contents Next