1 of 1 ·for & while

Lesson 1 · Python Foundation
Two ways to repeat.
Loops
Use a for loop to repeat a known number of times. First print a greeting three times. A while loop keeps going while its condition is true, so plan how it will stop.
Click to zoomTwo chapters ago you built a triangle with five print() statements, and the challenge asked what it would take to make it twice as tall. The answer was: write it all out again.
That's the problem loops solve, and you met it first in Scratch: repeat 4 versus eight separate blocks.
Python gives you two loops, and picking between them is the same question as in Scratch: do I know how many times?
10 more parts in this lesson
Walkthroughs, code labs, mini-games and the checkpoint quiz unlock when you buy the course.