Repetition (Iteration) Constructs

Consider the following example:

Find the sum of 10 numbers provided by the user.

This can be accomplished as follows:

The above solution is very long as well as difficult to understand , manipulate and communicate .

Observe that there were many repeated steps in obtaining input from the user.

The solution can be simplified by looping.

A general looping construct is shown below:

The solution can be simply implemented using looping:

Class Discussion: walk-through of solution is discussed.

This files used in this post can be downloaded here:

https://drive.google.com/drive/folders/1KjNcPQATyqh8quxnRjUDbJOgdzGvUY1P?usp=sharing

Homework:

Create an algorithm which uses repetition to output  the 12 times table from 1 to 12.

Updates

2022-10-6: Added files used in this post.

© 2020  Vedesh Kungebeharry. All rights reserved. 

One thought on “Repetition (Iteration) Constructs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s