# For vs While Loops > Ninth graders learn when to use each kind of loop — a FOR loop when you know how many times to repeat (or are looping over a collection), and a WHILE loop… **Computer Science** | **Grade 9** *A free lesson plan from K12 Academics. Source page: https://lessonplans.k12academics.com/k12-lesson-g9-cs-for-while.html* Ninth graders learn when to use each kind of loop — a FOR loop when you know how many times to repeat (or are looping over a collection), and a WHILE loop when you repeat until a condition changes. They check the ideas, then pick the right loop. **Copy link** works with Canvas, Schoology, Moodle and any other LMS — paste it in as a resource or assignment. ## Everything you need before the bell rings ### Learning Objectives Students will be able to… - Use a **for** loop. - Use a **while** loop. - Avoid **infinite loops**. - Pick the right one. Which loop should you use — and when? Project each one and have students answer about choosing a loop. ## 55 minutes, five moves Tap any phase to open the teacher moves and student actions. ### Hook — Which Loop? You want to repeat something — how do you decide which loop to use? #### 👩‍🏫 Teacher Moves - Pose the question. - Share ideas. - Set the goal. #### 🎒 Student Actions - Think. - Share. - Get ready. ### Use — For vs While Students learn. #### 👩‍🏫 Teacher Moves - Send students to For vs While Loops. - Note for = known count. - Note while = until a condition. #### 🎒 Student Actions - Answer. - Note it. - Note it. ### Modify — Use It Students practice. #### 👩‍🏫 Teacher Moves - Write a for loop. - Write a while loop. - Add a stopping condition. #### 🎒 Student Actions - For. - While. - Stop. ### Create — Create Students apply. #### 👩‍🏫 Teacher Moves - Pick a loop for a task. - Write it. - Avoid an infinite loop. #### 🎒 Student Actions - Pick. - Write. - Check. ### Reflect — Reflect Students close. #### 👩‍🏫 Teacher Moves - When do you use a for loop? - When a while loop? - Complete the exit ticket. #### 🎒 Student Actions - Say it. - Say it. - Complete the exit ticket. ## Built to the standards you report on Aligned to the CSTA K-12 Computer Science Standards and the ISTE Standards for Students. Use for and while loops. Justify the choice of loop. Test and debug loops. Reason about repetition. ## One lesson, every learner ### Multilingual Learners - For/while example cards. - Frame: "I use for when ___." - Trace each loop. ### Support & Access - Focus on for loops. - Use a template. - Count repeats. ### Stretch & Extend - Convert for to while. - Add a break. - Avoid off-by-one errors. ### What to gather - 📽️Screen / board - 🔁Loop cards - 💻For vs While Loops - 💻Python - 📓Notebooks - 🎫Exit-ticket slips ### Key terms - **for loop**: repeats a known number of times - **while loop**: repeats until a condition changes - **condition**: a true/false test - **iteration**: one pass of a loop - **infinite loop**: a loop that never stops - **collection**: a group to loop over - **counter**: tracks loop progress - **break**: exit a loop early ## Exit Ticket Preview the three formative checks. Tap “Sample answer” to see what mastery looks like — hide them before you print for students. ### Reflect: for vs while loops. Have students pick and write the right loop for a task. A printable loop sheet is in the CS library. ## Check your understanding **1. What does “for loop” mean?** - a group to loop over - repeats a known number of times *(correct)* - repeats until a condition changes - tracks loop progress “for loop” means: repeats a known number of times **2. Which word means: “repeats until a condition changes”?** - while loop *(correct)* - condition - collection - iteration “while loop” means: repeats until a condition changes **3. What does “condition” mean?** - one pass of a loop - a true/false test *(correct)* - tracks loop progress - a group to loop over “condition” means: a true/false test **4. Which word means: “one pass of a loop”?** - break - iteration *(correct)* - infinite loop - while loop “iteration” means: one pass of a loop **5. What does “infinite loop” mean?** - a true/false test - one pass of a loop - a loop that never stops *(correct)* - a group to loop over “infinite loop” means: a loop that never stops **6. Which word means: “a group to loop over”?** - while loop - collection *(correct)* - infinite loop - iteration “collection” means: a group to loop over ## Printable worksheet --- Full lesson page: https://lessonplans.k12academics.com/k12-lesson-g9-cs-for-while.html All lessons: https://lessonplans.k12academics.com/