Learn C Programming

Lesson 2 of 9 · Loops and Jump Statements

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

  1. The for header: init, condition, update
  2. The order the parts run in, traced
  3. A for is a while with its parts gathered
  4. Counting down, counting in steps, and for (;;)
  5. The loop variable lives only inside the loop
  6. Off by one: which comparison to write
  7. Leave the loop variable alone in the body
  8. Two counters and the comma
  9. Checking a loop against a formula