WHILE LOOP IN PYTHON
Loops are used to execute a piece
of code or set of statements multiple times in a program as long as the
condition is true. While loop is the basic loop structure in Python.
Syntax:
While (expression):
Statement(s)
Here, condition may be any logical
expression and statement(s) can be single statement or multiple statements. The
loop will iterate or execute until the condition is true. When the condition
becomes false, program comes out of the loop and remaining statements are
executed. In Python language, during any of the decision making, control
statements and looping indentation is very important because, it specifies the
set of statements to be a part of single code or block. Since no brackets are
used to specify the complete code with in, indentation is used.
In While loop, the main important
thing is the loop may never be executed if the condition is not satisfied and
it will execute the first statement after the while loop.
You can use while loop with if...else
as per the program requirement.
Watch my video to get the detailed
view of how to use while loop with a practical explanation.
Comments
Post a Comment