Loops and Control Statements (continue, break and pass) in Python Last Updated : 04 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Python supports two types of loops: for loops and while loops. Alongside these loops, Python provides control statements like continue, break, and pass to manage the flow of the loops efficiently. This article will explore these concepts in detail.Table of Contentfor Loopswhile LoopsControl Statements in Loopsbreak Statementcontinue Statementpass Statementfor LoopsA for loop in Python is used to iterate over a sequence (such as a list, tuple, string, or range). Python # Iterating over a list a = [1, 2, 3] for i in a: print(i) Output1 2 3 while LoopsA while loop in Python repeatedly executes a block of code as long as a given condition is True. Python # Using while loop cnt = 0 while cnt < 5: print(cnt) cnt += 1 Output0 1 2 3 4 Control Statements in LoopsControl statements modify the loop's execution flow. Python provides three primary control statements: continue, break, and pass.break StatementThe break statement is used to exit the loop prematurely when a certain condition is met. Python # Using break to exit the loop for i in range(10): if i == 5: break print(i) Output0 1 2 3 4 Explanation:The loop prints numbers from 0 to 9.When i equals 5, the break statement exits the loop.continue StatementThe continue statement skips the current iteration and proceeds to the next iteration of the loop. Python # Using continue to skip an iteration for i in range(10): if i % 2 == 0: continue print(i) Output1 3 5 7 9 Explanation:The loop prints odd numbers from 0 to 9.When i is even, the continue statement skips the current iteration.pass StatementThe pass statement is a null operation; it does nothing when executed. It's useful as a placeholder for code that you plan to write in the future. Python # Using pass as a placeholder for i in range(5): if i == 3: pass print(i) Output0 1 2 3 4 Explanation:The pass statement does nothing and allows the loop to continue executing.It is often used as a placeholder for future code.Exercise: How to print a list in reverse order (from last to the first item) using while and for-in loops. Comment More infoAdvertise with us Next Article Loops and Control Statements (continue, break and pass) in Python kartik Follow Improve Article Tags : Python Computer Science Fundamentals Practice Tags : python Similar Reads Ternary Operator in Python The ternary operator in Python allows us to perform conditional checks and assign values or perform operations on a single line. It is also known as a conditional expression because it evaluates a condition and returns one value if the condition is True and another if it is False.Basic Example of Te 5 min read Operator Overloading in Python Operator Overloading means giving extended meaning beyond their predefined operational meaning. For example operator + is used to add two integers as well as join two strings and merge two lists. It is achievable because '+' operator is overloaded by int class and str class. You might have noticed t 8 min read Python | a += b is not always a = a + b In Python, a += b doesn't always behave the same way as a = a + b, the same operands may give different results under different conditions. But to understand why they show different behaviors you have to deep dive into the working of variables. before that, we will try to understand the difference b 4 min read Difference between == and is operator in Python In Python, == and is operators are both used for comparison but they serve different purposes. The == operator checks for equality of values which means it evaluates whether the values of two objects are the same. On the other hand, is operator checks for identity, meaning it determines whether two 4 min read Python | Set 3 (Strings, Lists, Tuples, Iterations) In the previous article, we read about the basics of Python. Now, we continue with some more python concepts. Strings in Python: A string is a sequence of characters that can be a combination of letters, numbers, and special characters. It can be declared in python by using single quotes, double quo 3 min read Python String A string is a sequence of characters. Python treats anything inside quotes as a string. This includes letters, numbers, and symbols. Python has no character data type so single character is a string of length 1.Pythons = "GfG" print(s[1]) # access 2nd char s1 = s + s[0] # update print(s1) # printOut 6 min read Python Lists In Python, a list is a built-in dynamic sized array (automatically grows and shrinks). We can store all types of items (including another list) in a list. A list may contain mixed type of items, this is possible because a list mainly stores references at contiguous locations and actual items maybe s 6 min read Python Tuples A tuple in Python is an immutable ordered collection of elements. Tuples are similar to lists, but unlike lists, they cannot be changed after their creation (i.e., they are immutable). Tuples can hold elements of different data types. The main characteristics of tuples are being ordered , heterogene 6 min read Python Sets Python set is an unordered collection of multiple items having different datatypes. In Python, sets are mutable, unindexed and do not contain duplicates. The order of elements in a set is not preserved and can change.Creating a Set in PythonIn Python, the most basic and efficient method for creating 10 min read Dictionaries in Python Python dictionary is a data structure that stores the value in key: value pairs. Values in a dictionary can be of any data type and can be duplicated, whereas keys can't be repeated and must be immutable. Example: Here, The data is stored in key:value pairs in dictionaries, which makes it easier to 5 min read Like