While loops

  • Conditional iteration tests a condition to determine if a loop should continue
  • Called continuation condition
while <condition>:
    <loop statements>

Examples

x = 10
while x > 0:
    print(x)
    x = x - 1
10
9
8
7
6
5
4
3
2
1
count = 0
while (count < 10):
   # Point A
   print ("Olá...", count)
   count = count + 1
   # Point B
# Point C

Consider the following affirmations and say if they are right or wrong:

  1. count < 10 is always True at point C.
  2. count < 10 is always False at point B.
  3. count < 10 is always True at point A.
  4. count < 10 is always False at point C.
  5. count < 10 is always True at point B.