Skip to content
This repository was archived by the owner on Jun 4, 2019. It is now read-only.

Latest commit

 

History

History
38 lines (29 loc) · 880 Bytes

File metadata and controls

38 lines (29 loc) · 880 Bytes

Loops (While)

A loop statement allows to execute a block of code multiple times. Python supplies two type of loops:

  • while
  • for

The syntax of a while loop is:

while condition:
   statement

While loops repeat a target statement as long as a given condition is true.

count = 0
while count < 9:
    print('Loop iteration: ', count)
    count = count + 1

Python supports to have an else statement associated with a loop statement. The else statement is executed when the condition becomes false.

count = 0
while count < 9:
   print('Loop iteration ', count)
   count = count + 1
else:
   print('loop end')

Instructions Modify the count, so that condition and switch_loop must become true. Use else statement, to mark the end of a program and switch switch_end to value true.