Hello Friends๐
In Our Previous Blog, We have Learned the Basics of Python Programming Language & Simple Program in Python Programming Language.
Now In this Blog, We will learn about Looping Statement and its Programs in Python.
What is Looping Statement in Python Programming Language.
Looping Statement :- A loop in a programming language is a statement that contains instructions that are repeated over and over again until a certain condition is reached.
When a task has to be repeated again and again then loop helps us to remove the REDUNDANCY of the code.
Suppose you want to print your name five times, instead of writing the statement five times, you can use a loop.
Types of Loops in Python Programming Language
There are mainly two types of loops in the Python programming language.
- While Loop
- For Loop
While Loop :- In the while loop, first the condition is checked, then the statement is executed and it continues to execute until the condition becomes false.
Syntax of While Loop
while expression:
statement(s)
Example of While Loop - Program
i = 1
while i >= 5:
print("Number = ",i)
i += 1
======================
Output
Number = 1
Number = 2
Number = 3
Number = 4
Number = 5
For Loop :- The syntax of loops in Python is quite different from the rest of the programming language. Loop is used to iterate over a sequence (such as Lists, Tuples, Dictionaries & Sets, etc.).
Syntax of For Loop
for <Variable - Name> in <Sequence - Name>
statements
Great dude
ReplyDelete