Legacy - While Loops
- 01:21
Learn how to create "While" loops in Python.
Downloads
No associated resources to download.
Transcript
Let us now look at how to write while loops in Python. Before writing a while loop, we need to understand the Python supports two usual logical conditions from mathematics such as equal to not equal to, greater than, less than, greater than or equal to, less than or equal to. These logical conditions are used to write the values. Initially, before writing the loop, we have to define the variables that we shall use in the loop. With the while loop, we can execute a set of statements as long as the condition is true. Looking at the example on the screen, we want Python to print the value of I as long as is I less than 5. Every time I space it we wanted increment by two. The loop starts with a while and then the condition which is that followed by a column, the loop is then followed by a state but or an action that needs to be performed what's the condition is met. One thing to note is that the indentations are really important. One suggestion is to press enter once you reach the colon or the end of a light, rather than manually setting the indentation, let Python do the job for you.