Python 7

Python In While Loops | Python Tutorial #71 min read

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

Run Code

Output:

Run Code

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

Run Code

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:

Tanmay Sinha

Author

  • Tanmay Sinha

    Founder & CEO of MrProgrammer.in | I help Learning Freaks to Step into the World of Programming and Our Mission is to Provide High Quality and Valuable Content to Our Users! We believe that everyone has the potential to learn to code, and we are committed to making that happen. Our courses are designed to be engaging and interactive, and we offer a variety of learning paths to meet the needs of all learners. We are also committed to providing our learners with the support they need to succeed, and we offer a variety of resources to help learners learn at their own pace. If you are interested in learning to code, we encourage you to check out our courses. We are confident that you will find our content to be high-quality, valuable, and makes sense.

Leave a Reply