How to use while loops in Python

While loops allow you to execute a block of code repeatedly until a certain condition is met.

Here is an example of a while loop in Python:

# Initialize the counter
counter = 0

# Start the while loop
while counter < 10: # Print the counter print(counter) # Increment the counter counter += 1 # Print a message once the loop is finished print("Loop finished")