Introduction

Loops apply the same steps to many values. Start with a small collection so you can follow each iteration. A loop must eventually finish; make sure its condition or sequence moves toward an end.

Syntax & example

for number in range(1, 6):
    print(number)

Expected output

1
2
3
4
5

Common mistakes

  • Using a variable before assigning a value to it.
  • Mixing text and numbers without converting deliberately.
  • Skipping an empty input or a boundary value when testing.

Practice

Print the numbers from 1 to 5.

13px
main.pyYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-82 lines