8. Loops
A computer program can perform repeated tasks using loops. Loop is a powerful coding tool, because it helps us process thousands of data entry quickly and easily.
You can print out a list:
1
name_list = ["mary","john","paul","eric"]
2
3
for name in name_list:
4
print(name)
5
6
for name in name_list:
7
print("Hello " + name)
Copied!
You can also loop through specific range of items in a list:
1
for n in range(1,3):
2
print("Hello " + name_list[n])
Copied!
...which is the same as:
1
print("Hello " + name_list[1])
2
print("Hello " + name_list[2])
3
print("Hello " + name_list[3])
Copied!
Last modified 2yr ago
Copy link