For Loops

--Originally published at Hackerman's house

 

I have already talked about while loops in a previous post, this time im gonna be talking about the for loops. A while loop executes the loop as long as a certain condition is accomplished, in the case of the for loop, it is used when we know the amount of times that we want something to happen.

The syntax of this function is really simple.

list = [1, 3, 4, 5, 6, 7]

for n in list:

print(n)

We know that we want to repeat the loop with everything that is inside of the list this is one of the ways to use the for loop. If you don’t have a list of values you can also use the function range.

for x in range (2,15):

print(x)

Really simple and really useful.