Loops let you run a block of code over and over again. This is called iteration. Instead of copying and pasting code 10 times, loops do the repeating for you.
Why Use Loops?
Efficiency: Save time by repeating code automatically.
Automation: Useful for lists, counting, checking input, and more.
Cleaner Code: Fewer lines, better structure.
Letβs start by watching a short video to understand how loops work in programming.
π½οΈWatch & Learn
HD
Expand your knowledge
Follow along as your teacher draws examples on the live whiteboard to reinforce what you learned.
Live Whiteboard Viewer
Loading whiteboard...
The for Loop
for loops are great when you know how many times something should run. It repeats a fixed number of times.
for i in range(5):
print(i)
This prints: 0 1 2 3 4
The while Loop
while loops run as long as a condition is true. Itβs useful when you donβt know how many times the loop needs to run.
x = 0
while x < 5:
print(x)
x += 1
This also prints: 0 1 2 3 4
Comparing for and while
For loop: Use when you know how many times to repeat.
While loop: Use when you repeat until something changes.
Looping Through Lists
We can use loops to go through all items in a list.
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Try It Yourself!
Try these short challenges on your own or with your group.
πΏPopcorn Hack
What is the difference between a while loop and a for loop?
Response saved successfully!
Review & Practice
1/16
Flashcards (Static)
1/16
Answer:
Displays pre-loaded flashcards with definitions for review.
2/16
Flashcards (Student)
2/16
Answer:
Allows students to create and study their own flashcards, with CRUD functionality.
3/16
Video Player
3/16
Answer:
Embeds YouTube videos responsively and provides playback controls.
4/16
Code Prompt (Popcorn Hack)
4/16
Answer:
Lets students write and run Python/JavaScript code in real-time with instant feedback.
5/16
AI Comprehension Checker
5/16
Answer:
Generates practice questions from lesson content with multiple difficulty levels and provides feedback.
6/16
Feedback Poll
6/16
Answer:
Collects thumbs-up/thumbs-down feedback and allows students to leave comments.
7/16
Live Whiteboard
7/16
Answer:
Enables a shared whiteboard session for live collaboration and drawing with board code entry.
8/16
Multiplayer Quiz Game
8/16
Answer:
A real-time competitive quiz game with a live leaderboard and time-based challenges.
9/16
Interactive Sidebar
9/16
Answer:
Provides tools for dictionary lookups, notes, highlighting, and text-to-speech within the lesson content.
10/16
Text-to-Speech
10/16
Answer:
Reads selected text aloud using an external API, supporting auditory learning.
11/16
Highlighting
11/16
Answer:
Enables students to highlight text and associate notes with it for better study organization.
12/16
Feedback Data Visualization
12/16
Answer:
Displays real-time feedback collected through the poll system, integrated with Google Sheets.
13/16
Multiplayer Quiz Backend
13/16
Answer:
Uses Flask and Socket.IO to handle real-time multiplayer quiz interactions and store quiz data.
14/16
Spaced Repetition
14/16
Answer:
A technique used in the flashcard system to optimize review intervals based on retention.
15/16
Dynamic Content Loading
15/16
Answer:
Loads interactive features dynamically through `include` statements based on lesson requirements.
16/16
Responsive Design
16/16
Answer:
The system ensures that all interactive components (video, quizzes, code prompts) adapt to screen size.
π Marked for Review
Review key terms that you need, and add your own flashcards below too!
π Flashcard Notes
0 / 0
Add your own flashcards here.
Letβs play a live multiplayer quiz game!
Join Quiz Game
Test your knowledge
Answer quickly for higher scores!
Python Functions Quiz
Question 1/10
10
Quiz Completed!
You scored 0 points
0
Correct
0
Wrong
0
Points
Leaderboard
Weβd love your feedback:
πHow was this lesson?
Feedback submitted successfully!
Response Analytics Dashboard
Real-time feedback insights and trends
Loading response data...
Live Data
Homework Hacks
Count Down: Use a while loop to print numbers from 10 to 1, then "Liftoff!".
Sum of Numbers: Write a for loop to find the sum of numbers 1 through 100.
Filter Even Numbers: Loop through a list and print only the even ones.
Extra Practice
Optionally, you can try AI-generated questions to test your understanding of loops, or use this if you're coming back to study for a test on this lesson.