While loop in Python
While loop in Python Programming is a type of loop in which we pass conditions and loop continues to execute until condition is true.
What are loops?
Loops are basically use for running a same line of code multiple times. Suppose, we want to print any number(i.e, 1) multiple times(i.e, 100 times) then we don’t need to write a print statement 100 times, instead of we can use loop. We can put our single line print statement in a loop which consist a argument 100 in our case. The argument decides “How many times our code would be execute”. There are multiple types of loops in Python like for-loop, while-loop etc. Don’t worry I would tell you about every single loop in this Python Programming Series.
While-loop in Python Programming
When we want to give any condition. For example, We don’t want to terminate our loop until a condition is true. Suppose we want to print counting from 1 to 10 then we can put initialize our variable by 1. We then put a while loop with a condition(ie, run the loop until our variable is less than 11) and We would have to increment our variable in each iteration.
i=1 while(i<11): print(i) i=i+1
Here, This loop will print from 1 to 10. when our variable(i) will become 11. Our condition will become false and then loop will be end by itself.
Variable in Python Programming
Python variable is a symbolic name that is a reference or pointer to an object. Once an object is assigned to a variable, you can refer to the object by that name. But the data itself is still contained within the object. It is called variable because it’s value can be changed.
If you want to know about the for-loop in Python then you can go through my other blog in which I discussed about for-loop in Python.click here