© Sloan Kelly  2019
Sloan KellyPython, PyGame, and Raspberry Pi Game Developmenthttps://doi.org/10.1007/978-1-4842-4533-0_6

6. Making the Raspberry Pi Repeat Itself

Sloan Kelly1 
Niagara Falls, ON, Canada

A video game repeats the action until all the players’ lives have gone, or the end of the game has been reached. So far, we have only written programs that run through a sequence of commands and then terminate. With the use of certain Python keywords, we can get the computer to repeat a block of code when required, either using conditions or for a set number of times.

The for Loop

The ‘for loop’ in Python takes a list, and for each item in the list it performs a series of action. These actions are contained within the block of code that appears ...

Get Python, PyGame, and Raspberry Pi Game Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.