Loops
Loops are how we as programmers do the same thing over and over. Instead of copying and pasting the same line(s) of code back-to-back, which can get clunky if done a few times and downright ugly if done more than once or twice, all modern programming languages contain some variations on the construction of a loop, which permits iteration and repetition. Loops allow us to do things like counting or even implement the fundamental basic flow of a game. Perhaps in Scratch, you used the Repeat __ Times block, or the FOREVER block. In C, we have three main types of loops: for, while, and do-while. Let’s dive in!
-
Lecture
-
Shorts
-
Notes
-
Supplementary Resources
- Alex Allain on Loops in C tutorial
-
Thought Questions
- Why does C provide different types of loops?
- What does translating a loop to pseudocode look like? What about translating a loop to a flowchart?
- Why is using loops in computer programs so impactful?
-
Problems