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:
forUnderstand what a loop isrange()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 ..aftercd 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