Category: Loops
Python – continue keyword and loops
In this article, we will discuss the syntax and usage of the ‘continue’ keyword. We will also cover the examples of continue keyword in both while loop and for loop. In python, a ‘continue’ statement inside a loop can make the control jump back to the starting of the loop. If the interpreter encounters a …
Python: break keyword – Explained with examples
In this article, we will discuss how to use the break keyword in python to break the flow of loops. We will also cover examples of while loop and for loop with a break statement. “break” statement in python is useful to break the flow of a loop abruptly i.e. It can force a while …
Python: For Loop – Explained with examples
In this article, we will learn the syntax and usage details of for loop in python. Then we will look at various examples of the for loop. In python, we can iterate over a group of statements multiple times using a for loop. But the number of times these statements will be executed by a …
Python: while loop – Explained with examples
In this article, we will learn the syntax and usage of a while loop in python. Need of a while loop? In python, if we write some statements like this, Advertisements print(‘First line’) print(‘Sample text’) print(‘Last line’) The interpreter will execute these statements in sequential order, but only once from top to bottom. What if …
For Loop with two variables in Python
In this Python tutorial, you will learn to use for loop with two variables. Table Of Contents Introduction Using for loop with two variables to iterate over dictionary. Using for loop with two variables with zip(). Using for loop with two variables with enumerate(). Summary Introduction In python, for loop is used to iterate elements …
Combine For Loop & if-else statement in Python
In this Python tutorial, you will learn how to combine a for loop with if / if-else statements in Python. Table Of Contents Introduction Combine a for loop and if statements Combine for loop and nested-if statements in Python Combine for loop and if-else statements How to Combine for loop and nested if-else statements? Summary …
Loops in Python
3.1) The “while loop” in Python A while loop in python executes a group of statements or a suite of statements multiple times, till a given condition is True. Read More…… 3.2) The “for-loop” in Python Iterate over a group of statements multiple times using a for loop. But the number of times these statements will …