While Loop

Python While Loop is used to execute a block of statements repeatedly until a given condition is satisfied. And when the condition becomes false, the line immediately after the loop in the program is executed.
While loop falls under the category of indefinite iteration. Indefinite iteration means that the number of times the loop is executed isn’t specified explicitly in advance.
Statements represent all the statements indented by the same number of character spaces after a programming construct are considered to be part of a single block of code.
Python uses indentation as its method of grouping statements.
When a while loop is executed, expression is first evaluated in a Boolean context and if it is true, the loop body is executed.
Then the expression is checked again, if it is still true then the body is executed again and this continues until the expression becomes false.
With the while loop we can execute a set of statements as long as a condition is true.

a = 5
while a > 0:
    print("rguktweb")
    a = a-1
## Remember to decrement a,
## or else the loop will continue forever.

The while loop requires relevant variables to be ready.

The Break Statement

With the break statement we can stop the loop even if the while condition is true.

a = 13
b = 2
while b < a:
    print("hello world.")
    b = b+1
    ## or use 
    ## a = a-1
The Continue Statement

With the continue statement we can stop the current iteration, and continue with the next.

a = 10
while a > 0:
    a = a-1
    if a == 5:
        continue    
    print(a)
The Pass Statement

The Python pass statement to write empty loops. Pass is also used for empty control statements, functions, and classes..

a = 10
while a > 0:
    a = a-1
    pass    
print(a)
while loop with else

while loop executes the block until a condition is satisfied.
When the condition becomes false, the statement immediately after the loop is executed.
The else clause is only executed when your while condition becomes false.
If you break out of the loop, or if an exception is raised, it won’t be executed.
The else block just after for/while is executed only when the loop is NOT terminated by a break statement.

a = 10
while a != 0:
    print(a)
    a = a-1
else:
    print("loop completed.")

a = 10
while a != 0:
    print(a)
    if a == 5:
        break
    a = a-1
else:
    print("loop completed.")
Nested while loops

A nested loop is a loop inside a loop.
The "inner loop" will be executed one time for each iteration of the "outer loop".

a = 10
b = 5
while a > 0:
    c = 0
    while c < b:
        print("hello world.")
        c = c+1
    a = a-1
Sentinel Controlled Statement

In this, we don’t use any counter variable because we don’t know that how many times the loop will execute.
Here user decides that how many times he wants to execute the loop. For this, we use a sentinel value.
A sentinel value is a value that is used to terminate a loop whenever a user enters it, generally, the sentinel value is -1.

a = int(input("enter any Number."))
while a != 0:
    a = int(input("enter 0 to quit."))