9.while Loops in Python
9.while Loops in Python
Now as we know now what loops are and why they are
used, in this section, I will go directly towards the working
and syntax of while loop along with its comparison with
for loop and where to use it.
The syntax for while loop is simple and very much like for
loop. We have to use the keyword “while”, along with it we
have to put a condition in parenthesis and after that, a
colon is placed. The condition could be either true or
false. Until the condition is true, the loop will keep on
executing again and again. If we use a certain sort of
condition in our while loop that, it never becomes false
then the program will keep on running endlessly, until we
stop it by force. So, this kind of mistake in our syntax is
known as logical/human error.
For vs While: