For Loops

For Loop

start number

end number (-1)

loop number variable


for number in range (1, 6, 1):

         print("Loop count:" , number)

colon required

must indent (tab key)

indented lines will be repeated

Loop count: 1

Loop count: 2

Loop count: 3

Loop count: 4

Loop count: 5

Press F5 to run program:

simple iteration number

for loop (with break)

for number in range (3):

         password = input("Enter the password: ")

         if password == "fluffythecat123":


stops the loop

Enter the password: sonic

Enter the password: fluffythecat123

Press F5 to run program: