ProLesson 2 of 36 min read

How a for loop runs, step by step

Trace a for loop one pass at a time so you can predict exactly what it does and avoid off-by-one mistakes.

Programs are good at repeating work without getting bored. Adding up a hundred prices, checking every name in a list, or printing a times table all involve doing the same steps again and again. A for loop lets you write those steps once and have the computer repeat them for each item in a sequence.

Vidi Pro

Keep going with Pro.

The first lesson of every class is free. Pro opens every lesson in IELTS, Programming, Mathematics, Science and Data and AI, with practice questions.

Already have Pro? Log in to keep reading.

Written with AI help. Spotted a mistake? Tell us.