Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
The simplest form of a loop in Python is the while loop. So, let's make a working copy of while.py, while-working.py, and we'll go ahead and open our working copy there. The while loop is controlled with the while keyword, which we can see here, and then there is an expression. So, the expression gets evaluated, and if the expression is true, then the code inside the loop, the suite, is executed. After that code is executed, the expression is evaluated again, and if it's still true, the code gets executed again.
This continues until the expression is evaluated as false, and then the execution begins after the while loop. So, let's go ahead and run this, and there is our Fibonacci series. So, this expression is b<50, so as long as the result there is <50, the while loop will continue. So, if I were to increase this to say 150, save that, and run it, then we get a few more numbers out there in the Fibonacci series.
So, while is the simplest form of loop in Python, and you can see all it does is it evaluates this expression. As long as the expression is true, it executes the code in the while loop, and as soon as the expression is not true, the loop ends. So, that's the while loop in Python.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97405 Viewers
61 Video lessons · 84635 Viewers
71 Video lessons · 68844 Viewers
56 Video lessons · 101302 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.