Kayla Budzeak
2 min readJul 9, 2021

Have you ever wanted to go through something and do something with the things in it? No? Just me? Oh. Well, today we’re gonna cover just that.

Say for example you have a list of students, and you want to count how many students are within your list; we can do that with a for loop! For this example, we’ll use a python list where the elements will be names:

students = ["Monica", "Rachel", "Ross", "Chandler", "Joey", "Phoebe"]

With a for loop we can iterate through this and count the number of students:

count = 0
for item in students:
count = count + 1
print(count)

The above will print out the number 6, because as our loop iterates through our list it will add 1 to our count. If we wanted to see this in action we could place an additional print() statement within our loop and it would print out the count as it goes through!

count = 0
for item in students:
count = count + 1
print(count)
print(count)//this will be printed from within our for loop
1
2
3
4
5
6
//this one is printed after our for loop has been completed
6

for loops are wonderful tools for counting, and this may be the most frequent use you see of them!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kayla Budzeak
Kayla Budzeak

Written by Kayla Budzeak

I'm a Full-Stack Software Engineer, with a background in customer service, who recently graduated from Flatiron School. In my down time I love to bake & garden.

No responses yet

Write a response