05 Iteration (Condition Controlled) - Procedural Python
05 Iteration (Condition Controlled) - Procedural Python
3 Python:
Condition Controlled Iteration – WHILE Loop
Lesson Outcomes
• Carry out a number of programming tasks to practice
programming the WHILE loop construct
Literacy – Key Words
Iteration A programming construct, where code is executed repeatedly, either for a set number
of times or based on a conditional.
WHILE Loop A programming construct which enables a program to repeatedly execute code, whilst
a conditional evaluates to TRUE.
Iterations are therefore loops and in the python language there are two types of loop.
(they run for a set number of times) (they run whilst a condition is True)
while x <
==
>
!=
<>
>=
<= 0:
These are called conditions
Let's take a look more closely…
If n=5 and the condition was while x != 5 (not equal to 5) then the
Yes
loop would repeat until x equals 5.
bananas
bananas
bananas
bananas
bananas
bananas
bananas
bananas
bananas
bananas
bananas
x=0
bananas while x == 0:
bananas
bananas
print(“bananas”)
cheese
cheese
cheese
cheese
x=0
cheese while x == 0:
cheese
cheese
print(“cheese”)
cheese
cheese
cheese
cheese
cheese
cheese
cheese