0% found this document useful (0 votes)
38 views2 pages

Iteration 1

The document discusses two types of iterative loops - for loops and while loops. For loops are used when repeating a procedure a given number of times or plugging in successive integers. While loops are used when iterating until a certain condition is met or when the number of loops is known in advance. The document also defines what an iterator is - a mechanism to step through elements of a collection one by one, with each element delivered exactly once.

Uploaded by

mothusiamossello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Iteration 1

The document discusses two types of iterative loops - for loops and while loops. For loops are used when repeating a procedure a given number of times or plugging in successive integers. While loops are used when iterating until a certain condition is met or when the number of loops is known in advance. The document also defines what an iterator is - a mechanism to step through elements of a collection one by one, with each element delivered exactly once.

Uploaded by

mothusiamossello
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

ICT Grade 9

WHAT IS AN ITERATIVE LOOP?


Definition: Iteration is when the same procedure is repeated multiple times. Some examples
were long division, prime numbers, and the calculator game. Some of these used recursion as
well, but not all of them.

Two Types of Iterative Loops


1. for loop: used when you want to plug in a bunch of successive integers, or repeat a
procedure a given number of times
The for structure:

for x in __1_: __10_ (You can put your own values, starting point and end.)
(Do something)

for (int x=0; x=even numbers; x++)// general for high level language
Examples
for can also let you do something a certain number of times; you don’t even need to apply the
value of n.
Try this:
for n in 1:10

println (“School is an interesting place to be!”) end

Iterators
What if we want to traverse a collection of objects?
A common scheme for stepping through all elements in any collection or container, is called
an iterator

Madam Palesa Libe


An iterator is a mechanism used to step through the elements of a collection (container) one by
one

• Each element is “delivered” exactly once.

2. while loop: used when you want to iterate until a certain condition is met, or when you
know in advance how many loop
A while loop is used when you want to iterate until a certain condition is met, or when you
know in advance how many loops to run.

The format goes:


while (condition not met)

(do a bunch of stuff)


end

Madam Palesa Libe

You might also like