For instruction

One of the instructions used to iterate is the for instruction.

				

The for instruction can be read as "for everything in a list, run the following code".

The pattern is

for value in sequence:
    # code block

The sequence is a list such as numbers or strings

				

The value is a variable which is assigned the value of the current item in the sequence. It helps to give it a name that matches the type of item we are iterating over.

				

When to use for and when to use while

A for loop is great for data in a list or data that can be placed in a list. It is nice to use as you don't need to have a separate counter variable.

A while loop is good for looping an unknown amount of times, as it has a condition you can control.