For Loops
What happens when we want to program reasonably similar tasks for hundreds of different lines of data? Are we going to write a program with 900 lines of code? No! We'll use for loops!
By translating our tasks into for loops, we can have a few lines of code execute billions of tasks. And when combined with if statements (next chapter), we can really start to analyze data in complex and efficient ways.
Here we'll dip our toes in by learning the general behavior and logical errors that can arise. The syntax isn't super complicated, so you can start off with the set of snippets until you have it down, and in the next section we'll start using for loops to analyze data in real world applications.
Task
Write a program with a nested for loop that:
- Creates a blank matrix;
- Assigns entry (i,j) of the blank matrix to i(jβ1) for 1β€iβ€7 and 1β€jβ€7.
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.85
For Loops
Swipe to show menu
What happens when we want to program reasonably similar tasks for hundreds of different lines of data? Are we going to write a program with 900 lines of code? No! We'll use for loops!
By translating our tasks into for loops, we can have a few lines of code execute billions of tasks. And when combined with if statements (next chapter), we can really start to analyze data in complex and efficient ways.
Here we'll dip our toes in by learning the general behavior and logical errors that can arise. The syntax isn't super complicated, so you can start off with the set of snippets until you have it down, and in the next section we'll start using for loops to analyze data in real world applications.
Task
Write a program with a nested for loop that:
- Creates a blank matrix;
- Assigns entry (i,j) of the blank matrix to i(jβ1) for 1β€iβ€7 and 1β€jβ€7.
Thanks for your feedback!