Using for and while loops in Python

Now that Python can make decisions, how do we apply those decisions repeatedly?

In the last article, we learned how to guide Python through multiple levels of decision-making using nested if statements. But making decisions is only part of what makes Python pretty powerful.

Picture this: You've just landed your first data analysis task. Your dataset contains 9,000 respondents, and you need to perform the same check on every single record. After writing the same line of code a few times, and dodging errors, you stop and think: There has to be a better way than copying and pasting this thousands of times... right?

There is. It's called a loop, and by the end of this article, you'll know exactly how to use one, and get that task done in a fraction of that time.