Step 1 · Read and run
Two ways to count
These two loops print the same thing.
- A for loop is count-controlled: you know how many times it will run before it starts.
- A while loop is condition-controlled: it runs until a comparison becomes False, however long that takes.
You'll see these two names in exam questions. When you know how many times (10 questions, 7 days), for is shorter and can't loop for ever. When you're waiting for something (the right answer, a stopping value), use while.
Run the program to carry on.