Main content
Resources
Course: Resources > Unit 1
Lesson 4: Computer programming teachers- Programming content overview
- Tracking progress of programming students
- Classroom debugging guide
- Pair programming in the classroom
- Teaching guide: Intro to JS - Drawing Basics
- Teaching guide: Intro to JS - Coloring
- Teaching guide: Intro to JS - Variables
- Teaching guide: Intro to JS - Animation basics
- Teaching guide: Intro to JS - Interactive Programs
- Teaching guide: Intro to JS - Resizing with variable expressions
- Teaching guide: Intro to JS - Text and strings
- Teaching guide: Intro to JS - Functions
- Teaching guide: Intro to JS - Logic and if statements
- Teaching guide: Intro to JS - Looping
- Teaching guide: Intro to JS - Arrays
- Teaching guide: Intro to JS - Objects
- Teaching guide: Intro to JS - Object-oriented design
- Programming classroom handouts
- Additional programming projects
- Lesson plans: teaching programming in the classroom
- Programming case study: Encouraging cross-disciplinary projects
- Programming case study: Going beyond the KA curriculum
- Programming case study: Teaching an elementary school class
© 2023 Khan AcademyTerms of usePrivacy PolicyCookie Notice
Teaching guide: Intro to JS - Looping
This is a teaching guide for the Intro to JS lesson on Looping.
What the student will learn
- How to use loops to repeat code, changing a value in the code sequentially each time (like to draw a row or column of shapes).
- The syntax for a
while
loop and afor
loop. - How to nest loops inside each other, a useful technique for changing two dimensions of values (like to draw a grid of shapes).
The student will be able to write code like:
Where students struggle
- Students sometimes forget that they actually have to use the loop counter variable in their shape commands - otherwise their program will just draw a bunch of shapes on top of each other.
- Students may wonder when they should use a
while
loop versus afor
loop. Awhile
loop is the most general kind of loop, afor
loop is a more specific syntax that’s great for iterating through a sequence of numbers. For most drawings and animations, students will want to use afor
loop. - Students often forget all the parts of the
for
loop header. They can remember it by checking out the documentation example. Remind them that they don’t have to memorize programming syntax at first, as they will often have documentation - the important thing is to practice using the syntax and to understand it. - Students may write loops with the classic "off by one" error. That’s when their condition isn’t quite right, because they’re stopping one iteration too early or too late. Encourage them to think carefully about their condition, and what the values will be in the final iteration of code that will be executed.
Additional materials: Unplugged activities
An "unplugged" activity is one that you can do with students without needing to use a computer at all. They can help convey concepts in a more visceral way, and they can also be a backup activity for when computers fail.
Code.org offers a For Loops Fun activity (see overview video, lesson plan, and example in-class video).
Additional materials: Discussion questions
These are questions that you can ask students individually after they've done the lesson, or lead a group discussion around, if everyone's gotten to the same point.
- Look back at previous programs your students have made. Find ones with rows/columns of shapes, and ask students to point out where they could use loops. Perhaps if they have time, they can upgrade them.
- Look around the room. If you were drawing the room, where would you use loops?
Additional materials: Trivia questions
These can be fun to do as a class after everyone’s gotten through the lesson. They can also lead to discussion about which questions are the hardest. Play them on Quizizz.