Lesson 4: Loops
Learning Outcomes
- Students will understand and explain what a loop is.
- Students will implement loops in coding practice.
- Students will assess and solve complex problems using loops.
- Students will build complex problems including detecting if a number is prime.
Materials
How It Works
This is the final lesson on the basics of programming in C. Upon completion of this
programming unit, students should be able to do a variety of simple problems that
utilize math, printing and scanning, and if and else statements. The final lesson
will be on loops which are simple functions but highly powerful because they cut down
on programming time if you need to check or add together vast quantities of items.
Activity
- Part 1: Define loops
- Part 2: Detect prime numbers
- Part 3: “for” loops and “while” loops
Assessment
- Use a for loop to print out all the numbers from 1 to 1000.
- Use a while loop to print out all the numbers from 1 to 1000.
- If a for loop that looks like this:
For(int I = 0; I <20; I++)
{Printf(“%d\n”, I);}
How many times will the loop run through?
- Use a for loop instead of a while loop with the code used to find prime numbers in Part 2.
Additional Resources
- Lesson 4 Loops Lesson plan
- Vocabulary
- Teachers Guide
- https://www.w3schools.com/
- https://www.geeksforgeeks.org/c-programming-language/
- https://replit.com/languages/c