In this Tutorial We Will Learn About While Loops In Python, While Loops are the Most Important Part In Python And We Use Loops In Python Do The Tasks repetitively For Example If Someone Says you to Print Your Name For 100 Times, But the Condition You Don’t Have To Write 100 times then We can Use Loops In Python to Perform This Task. So Let’s Start With This Tutorial If You Have Not Accessed The Python Complete Course Access Here:
While Loops
While Loops is used to Perform Task a Block of Code Repeatedly Until a Condition Is True & Executed. And If the Loop is false the In the Program is Executed Again.
Example:
i = 10
while i < 15:
print(i)
i += 1
Output:
10
11
12
13
14
The while loop requires the relevant variables to be available, in this example we need to define an indexing variable, i, which we set to 1.
Break Statement
Break System In Python Stops the Loop When the Given Condition is Satisfied..
For Example:
i = 5
while i < 6:
print(i)
if i == 10:
break
i += 1
Output:
Continue Statement
With the continue statement, we can stop the current iteration and continue with the next iteration
Example:
i = 5
while i < 2:
print(i)
if i == 6:
continue
i += 1
Output:
1
2
3
4
5
Else Statement
Else Statement Run the Block Of Code Once the Condition is No Longer True.
i = 1
while i < 4:
print(i)
i += 1
else:
print("i is greater than the given number")
Access Complete Python Course Here:
- Which is the Best Operating System for Programming? Here are 3 OS to Consider - August 24, 2024
- Top 10 Cybersecurity Threats to Watch Out for in 2024 - August 17, 2024
- How Much Do Ethical Hackers Earn in India Per Month (Salary Guide) - August 11, 2024