Skip to content

Loops (For Loops)

Let's use loops to easily create many objects! ๐Ÿ”„


Learning Goals

When you finish this lesson, you'll be able to do the following:

  • for Understand what a loop is
  • range() Learn how to use functions
  • Learn how to use loops to create many objects

Take a look at the code

Below is code that uses a loop to create many cubes! ๐Ÿ”„

You can see how the repeating part runs the same code over and over! Watch it spin like a carousel as it makes cubes! ๐ŸŽ 

๐Ÿ“‚ Folder: two_control_flow / ๐Ÿ“„ File: volumetric_cube_loops.py

โšก Don't remember how to run it? (click)
  • Move to terminal: cd .. after cd folder_name
  • Run: python filename.py (autocomplete with the Tab key)
  • Exit: Alt+F4 (Win) / Cmd+Q (Mac)

๐ŸŽฎ Controls

Most games use the standard control scheme:

  • WASD Or Arrow keys: move
  • Mouse: adjust view / aim
  • Left click: shoot / interact
  • Space: jump (platformer games)
  • Tab: toggle slow motion (slow_motion.py)
  • Escape: quit the game