Loops
Python - A Quick Start for existing Programers
2 min read
Published Sep 16 2025, updated Sep 30 2025
Guide Sections
Guide Comments
While loops
While loops run the indented code repeatedly while the condition is True:
To skip to the next condition check you can use the continue statement:
So this example won't print out 3 as the continue statement will take the flow back to the condition check and then increment i to 4.
To break out a while loop you can use the break statement:
So this example, the last number printed will be 3 and then the while loop is ended.
To run code when the while loop finishes and the condition changes to False, use the else: statement:
The else section will only be ran if the loop naturally gets to the end and the condition changes to False. If the while loop has a break statement ran, then the else section is skipped.
For loops
To loop through 10 iterations from 0 -> 9:
To loop through 1 -> 10:
To loop through 2 -> 10, with a 2 step, so every other number:
You can use the break, continue and else: statements in a for loop, in the same way you can in a while loop.
To loop through a list:
To loop through a list and have the elements index:
The first variable after the for is for the index, and the second is for the value. You need to use the enumerate function to wrap the list.














