How to Check End of For Loop in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In Python, we often use loops to iterate over a collection like list or string. But sometimes, we may want to know when the loop has reached its end. There are different ways to check for the end of a for loop. Let's go through some simple methods to do this.Using else with For Loop (Most Efficient)The simplest way to check when a for loop has ended is by using the else clause. The else block after a for loop runs only when the loop has finished all iterations without being interrupted by a break statement. Python # Loop through numbers from 0 to 2 (range(3) generates 0, 1, 2) for a in range(3): print(a) else: print("End of loop") Output0 1 2 End of loop Other techniques that give us different levels of control and flexibility depending on the needs of our code are:Table of ContentUsing enumerate() to Track IterationUsing For Loop CounterUsing enumerate() to Track IterationSometimes we need to know the current index of the loop and also check if it's the last iteration. We can use the enumerate() function to get both the index and the value. Python for a, b in enumerate([10, 20, 30]): # Check if the current index 'a' is the last index (i.e., len(list) - 1) if a == len([10, 20, 30]) - 1: print("Last iteration") print(b) Output10 20 Last iteration 30 Using For Loop CounterIf we want even more control over the loop, we can use a counter to track iterations manually. Using For loop method is more complex but gives flexibility. Python a = [100, 200, 300] #Assign '0' to Counter variable counter = 0 for b in a: # Increment the counter by 1 for each iteration counter += 1 if counter == len(a): print("End of loop") print(b) Output100 200 End of loop 300 Create Quiz Comment P pragya22r4 Follow 0 Improve P pragya22r4 Follow 0 Improve Article Tags : Python Python Programs python Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like