top of page

Loops

A loop is a control structure that can execute a statement or group of statements repeatedly. Python has three types of loops: while loops, for loops, and nested loops.

while loop

A while loop will repeatedly execute a code block as long as a condition evaluates to True.

The condition of a while loop is always checked first before the block of code runs. If the condition is not met initially, then the code block will never run.

Screen Shot 2025-08-24 at 9.27.08 PM.png

for loop

A for loop can be used to iterate over a list of items and perform a set of actions on each item. The syntax of a for loop consists of assigning a temporary value to a variable on each successive iteration.

Screen Shot 2025-08-24 at 9.27.39 PM.png

nested loop

Loops can be nested inside other loops. Nested loops can be used to access items of lists which are inside other lists. The item selected from the outer loop can be used as the list for the inner loop to iterate over.

Screen Shot 2025-08-24 at 9.37.47 PM.png

Teacher don't teach me nonsense  

                                       

                     - Fela Kuti

bottom of page