Module 3

for loops

Repeating an action for each item.

Do this for each one

A for loop repeats a block of code for each item in a sequence. The most common use is looping through the characters of a string.

Python
for letter in "ABC":
    print(letter)
A B C

The variable letter takes each value in the string, one at a time. The indented block runs once for each value.

A for loop
Describe the task onceComputer repeats it every time
Runs the block once for each item.
Your task

Loop through text

  • Loop through the string ATGC and print each character.