While Loop

While Loop:
while loop is a standard workhorse of many languages. Essentially, the program will continue doing something while a certain condition exists. As soon as that condition is no longer true, the loop stops. the Python while statements is , again, similar to other languages

While Loop
While Loop
Here's the main format:
while<test>:    #loop test
<code block>   #loop body
else: #optional else statement
<code  block>    #run if didn't exit loop with break
break and continue work the exact same as in C.The equivalent of C's empty statement(a semicolon) is the pass statement,and Python includes an else statement for use with  breaks.
For example of while loop:
print('The count is:',counter)

The count is:0
The count is:1
The count is:2
The count is:3
The count is:4
The count is:5
The count is:6
The count is:7
The count is:8
The count is:9
Translate »