๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_for_loops.asp
Python For Loops
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string)....
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_lists_loop.asp
Python - Loop Lists
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... Learn more about for loops in our Python For Loops Chapter.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_while_loops.asp
Python While Loops
Python Examples Python Compiler ... Bootcamp Python Certificate Python Training ... With the while loop we can execute a set of statements as long as a condition is true. ... Note: remember to increment i, or else the loop ...
๐ŸŒ
W3Schools
w3schools.in โ€บ python โ€บ loops
Python Loops - W3Schools
1 * 1 = 1 1 * 2 = 2 2 * 1 = 2 2 * 2 = 4 3 * 1 = 3 3 * 2 = 6 4 * 1 = 4 4 * 2 = 8 5 * 1 = 5 5 * 2 = 10 ยท These statements are used to change execution from its normal sequence. Python supports three types of loop control statements: ... for letter in 'TutorialsCloud': if letter == 'C': pass print ('Pass block') print ('Current letter is:', letter)
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_dictionaries_loop.asp
Python - Loop Dictionaries
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... You can loop through a dictionary by using a for loop....
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_continue.asp
Python Continue For Loop
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... With the continue statement we can stop the current iteration of the loop, and continue with the next: ... fruits = ["apple", "banana", "cherry"] for x in fruits: if x == "banana": continue print(x) Try it Yourself ยป
๐ŸŒ
GitHub
github.com โ€บ pydawan โ€บ w3schools-python-tutorial โ€บ blob โ€บ master โ€บ loops.py
w3schools-python-tutorial/loops.py at master ยท pydawan/w3schools-python-tutorial
# The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3): ... # The else keyword in a for loop specifies a block of code to be executed when the loop is finished:
Author ย  pydawan
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ python โ€บ python_lists_loop_en.html
Python Loop Lists. Lessons for beginners. W3Schools in English
Python - Loop Lists. Loop Through a List. Loop Through the Index Numbers. Using a While Loop. Looping Using List Comprehension. Examples. Lessons for beginners. W3Schools in English
Find elsewhere
๐ŸŒ
W3Schools
w3schools.io โ€บ languages โ€บ python-for-loop
Python Tutorial - Learn Python Programming with examples - w3schools
initialization : variable is initialized and sets the initial value Condition: Python condition that evaluates true and false. It is used to test whether the loop continues or exits. increment/decrement: updated variable value by add/subtract Syntax: for( initialization; condition;increment/decrement){ //code statements body } ... s = 'hello' for c in s: print(c) Looping through a dictionary: Copy code # Print the keys and values of a dictionary emps = {'john': 1, 'eric': 2, 'mark': 3} for name, id in emps.items(): print(f'{name}: {id}') Looping with a counter: # Print the numbers 0 to 9, along with their indices numbers = ['one', 'two', 'three'] for i, number in enumerate(numbers): print(f'{i}: {number}') These are just a few examples of the types of for loops you can use in Python.
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Loops
Loops - Learn Python - Free Interactive Python Tutorial
If a break statement is executed inside the for loop then the "else" part is skipped. Note that the "else" part is executed even if there is a continue statement. ... # Prints out 0,1,2,3,4 and then it prints "count value reached 5" count=0 while(count<5): print(count) count +=1 else: print("count value reached %d" %(count)) # Prints out 1,2,3,4 for i in range(1, 10): if(i%5==0): break print(i) else: print("this is not printed because for loop is terminated because of break but not due to fail in condition")
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_else.asp
Python For Else
for x in range(6): if x == 3: break print(x) else: print("Finally finished!") Try it Yourself ยป ยท Python For Loops Tutorial For Loop Through a String For Break For Continue Looping Through a Range Nested Loops For pass
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_challenges_for_loops.asp
Python For Loops Code Challenge
Test your understanding of Python for loops by completing a small coding challenge. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ struggling to understand for loops in python
r/learnpython on Reddit: Struggling to understand for loops in Python
September 9, 2025 -

Hey everyone, Iโ€™m learning Python and I feel really stuck when it comes to for loops. I understand the basic syntax like:

for i in range(5):
    print(i)

But when I try to apply loops to real problems, I get confused. For example, looping through a list or using range with different start/stop/step values trips me up. Sometimes I donโ€™t know when to use for item in list versus for i in range(len(list)).

It feels like I understand loops in isolation but not how to use them properly in practical code.

Can someone explain in a simple way how to think about for loops, and maybe give me some beginner-friendly challenges/exercises so I can practice the right way?

Thanks a lot!

Top answer
1 of 5
10
If we stay with the example of a list, think of it this way: Imagine you have a list with elements [a,b,c] And you need to loop through the list for some action The question then is, do you need the actual elements, for example because you want to validate them or something? In that case going with the actual element in "for i in list" is the way to go. However, if you need the indexes of the items, for example for comparing or checking where in an ordered list items are, going with "for i in range(len(list))" is the way to go, as it allows you to check the current element of the list with a simple "list[i]" while being able to do something with the index itself. Ideally very often you would use something more descriptive than "i" if you need to do a bigger operation with it in order to makeit clear to the reader of your code what the selected item/index is for Please excuse my poor code formatting, I am on mobile, but I hope this helped you a little.. TLDR: It depends on use case which way to use for loops
2 of 5
4
For the most part it's a matter of convenience and practicality. Let's say you have some kids in a line, and you want to say good morning to each one. Then you would just iterate over their names. But let's say that you also want to give a present to each one, and you need to give the first gift to the first kid, the second gift to the second kid, and so on... Then you can just use the number, and you'd use the same number both for the kids and the gifts. If you're cool you can use enumerate too.
๐ŸŒ
Codecademy
codecademy.com โ€บ learn โ€บ learn-python-3 โ€บ modules โ€บ learn-python3-loops โ€บ cheatsheet
Learn Python 3: Loops Cheatsheet | Codecademy
The range() function can be used to create a list that can be used to specify the number of iterations in a for loop. ... An infinite loop is a loop that never terminates. Infinite loops result when the conditions of the loop prevent it from terminating. This could be due to a typo in the conditional statement within the loop or incorrect logic. To interrupt a Python program that is running forever, press the Ctrl and C keys together on your keyboard.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_tuples_loop.asp
Python - Loop Tuples
Python Examples Python Compiler ... Q&A Python Bootcamp Python Certificate Python Training ... You can loop through the tuple items by using a for loop....
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ python-for-loop.php
Python for loop
September 20, 2024 - It is widely used in for loops. Here is the syntax. ... In this example, we count the number of even and odd numbers from a tuple. numbers = (1, 2, 3, 4, 5, 6, 7, 8, 9) # Declaring the tuple count_odd = 0 count_even = 0 for x in numbers: if x % 2: count_odd+=1 else: count_even+=1 print("Number of even numbers :",count_even) print("Number of odd numbers :",count_odd)
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ for-loop
Python for Loop (With Examples)
In Python, we use a for loop to iterate over various sequences, such as lists, tuples, sets, strings, or dictionaries. The for loop allows you to iterate through each element of a sequence and perform certain operations on it. In this tutorial, we will explore how to use the for loop in Python, ...
๐ŸŒ
W3Schools
w3schoolsua.github.io โ€บ python โ€บ python_while_loops_en.html
Python While Loops. Lessons for beginners. W3Schools in English
Python While Loops. Python has two primitive loop commands: while loops, for loops. The while Loop. The break Statement. The continue Statement. The else Statement. Test Yourself With Exercises. Examples. Lessons for beginners. W3Schools in English
๐ŸŒ
Serverspace
serverspace.io โ€บ support โ€บ help โ€บ for-loop-python
Python 3 For Loop Explained: Syntax and Practical Examples
June 1, 2025 - Learn how to use a for loop in Python 3 to iterate over lists efficiently. This tutorial also covers running Python programs within a virtual environment on Ubuntu 22.04, helping you manage dependencies and improve your development workflow.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_for_range.asp
Python Looping Through a Range
The range() function defaults to increment the sequence by 1, however it is possible to specify the increment value by adding a third parameter: range(2, 30, 3): ... Python For Loops Tutorial For Loop Through a String For Break For Continue For Else Nested Loops For pass