Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
184_notes:loops [2022/04/20 14:36] – woodsna1 | 184_notes:loops [2022/05/07 01:19] (current) – woodsna1 | ||
---|---|---|---|
Line 26: | Line 26: | ||
You guessed it--in just a few lines, this code prints the numbers from 1 to 100. Let's break down what it's doing. | You guessed it--in just a few lines, this code prints the numbers from 1 to 100. Let's break down what it's doing. | ||
+ | ==== Lecture Video ==== | ||
+ | |||
+ | {{youtube> | ||
==== While Loops ==== | ==== While Loops ==== | ||
Line 83: | Line 86: | ||
row += 1 | row += 1 | ||
</ | </ | ||
- | This code is different. | + | In the above code, there are two separate while loops, with different |
+ | |||
+ | When you write code with a nested loop, it's important to carefully consider where each line of code belongs. In the above code, the column variable will be set to 1 eight times, moving back to the first column in each new row. The row variable is also only increased eight times, because it is not within the inner loop. If we forget to set the column variable back to 1, or increase the row variable 64 times, the code will not do what we intend. |