Module 6 · Loops and Jump Statements
for: Init, Condition, Update, Traced
Free with an accountReading
Bob had one job before the school raffle: print the ticket numbers 1 to 10. He typed a loop in a hurry and sent the list to the printer. It stopped at 9. The owner of ticket 10 found out at the prize table.
Sign in to read
This lesson is free, with an account
An account costs nothing and opens every lesson in this track that is not marked Pro, on every device you read on.
What is inside for: Init, Condition, Update, Traced
- The for header: init, condition, update
- The order the parts run in, traced
- A for is a while with its parts gathered
- Counting down, counting in steps, and for (;;)
- The loop variable lives only inside the loop
- Off by one: which comparison to write
- Leave the loop variable alone in the body
- Two counters and the comma
- Checking a loop against a formula