Legacy - While Loops Workout
- 02:03
Learn how to create "While" loops in PyCharm.
Downloads
While Loops - Python Workout FilesTranscript
Let us now look at how to write while loops in Python. Before writing while loops, we have to understand that the basic mathematical logical conditions like equal to, not equal to, less than, greater than, less than or equal to a greater than or equal to, can be used along with while loops as conditions. When writing the while loop, we have to first define a variable, let us define a variable current assets equals to 10. And this is millions. Remember that commenting in Python is done using a hash, meaning anything that follows a hash will not be included in the code and also will not be included when executing the code. Now, what we want to do is that while current assets is less than 70, in millions 70 Millions, we want byton to print the current assets and then increase the current assets by 10 Million and Reloop it again until the condition is met. So, it starts with a while current assets is less than 70, which is in millions call it and enter for indentation. We want Python to print the current assets. And then we want the current assets to increase by 10 million. And we write 10 in millions because this is the first time we're running the code we have to right click on the tab and select this perfect. The output pays 10 20 Does an increment by 10 in millions until 60 Perfect after printing 60 When the value gets into the next stage, we are asking the current assets to be increased by 10. So which means it goes up to a 70 when this pass back into the loop 70 is not strictly less than 70 meaning that's where the code exits. Perfect.