Skip to content

ADVERTISEMENT

Home » Blogs » Python In While Loops | Python Tutorial #7

Python In While Loops | Python Tutorial #71 min read

Python 7

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

ADVERTISEMENT

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:

ADVERTISEMENT

Leave a Reply