Legacy - For Loops Workout
- 02:00
Learn how to create "For" loops in PyCharm.
Downloads
For Loops - Python Workout FilesTranscript
Let us now look at how to build for loops in Python. Before building for loops, we have to know that the basic mathematical logical conditions are true for when building for loops, this can be used during the process of building. These logical conditions are equal to, not equal to, less than, greater than, less than or equal to and greater than or equal to. Now, moving to the link for loops, let us define our list of terms, which consists of M&A, FIG and FICC. Now we want to build a for loop that reads through the list and prints the terms from the list. So we say for a variable x in terms print x, meaning it should print the terms from the list. Because this is the first time we are writing the code, we have to right click on the tab and select Run. Perfect. It runs to the list and pastes the terms. Now imagine you've got a list which is 10,000 words long. How do you know when the list has ended or the loop has ended going through the list? We can do something that we did for the if statements, we can write an else a contradicting statement meaning for x in the terms Cryptex 'else' meaning when this has been finished searching, print 'finished printing the list' and if we run the season, the shortcut Shift f1 Perfect. If you look at it, it goes through the list. It prints the terms and after the last term it says okay, I finished printing the list. Perfect. It works