image
Educational Outreach

Introduction to Programming

Lesson 4: Loops

Intro to programming

 

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 

  1. Part 1: Define loops
  2. Part 2: Detect prime numbers
  3. Part 3: “for” loops and “while” loops 

Assessment

  1. Use a for loop to print out all the numbers from 1 to 1000.
  2. Use a while loop to print out all the numbers from 1 to 1000.
  3. 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?
  1. Use a for loop instead of a while loop with the code used to find prime numbers in Part 2.

Additional Resources

  1. Lesson 4 Loops Lesson plan
  2. Vocabulary
  3. Teachers Guide
  4. https://www.w3schools.com/
  5. https://www.geeksforgeeks.org/c-programming-language/
  6. https://replit.com/languages/c