InfoparkDailyCAREER TOOLS

Python · Lesson 5 of 9

Loops

for loops with range(), looping over lists, while, break and continue.

for repeats once for every item in a sequence. range(start, stop) produces numbers up to (not including) stop.

while repeats as long as a condition is true — make sure something inside changes so it eventually stops.

break leaves the loop immediately; continue skips to the next round. enumerate(items) gives you the position and the item together.

Try it yourself

Press Run to see the output.

Edit and press Run (or Ctrl/⌘ + Enter). Python runs in your browser — the first run downloads the Python engine and takes a few seconds.

Key points

  • range(a, b) stops before b.
  • enumerate() gives index and item.
  • Every while loop needs a way to finish.

Quick check

Which numbers does range(2, 5) produce?

Practice task

Print the multiplication table of 9 from 9 × 1 to 9 × 10 using a for loop and an f-string.

Interview corner

How would you loop over a dictionary's keys and values?

Use .items(): for key, value in data.items(): ... — it yields pairs.

What does the else clause on a loop do?

A loop's else block runs only if the loop finished without hitting break. It is handy for search loops: else means 'not found'.

Further reading

Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.

Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.