

Python - Introduction to While Loops
Presentation
•
Computers
•
8th - 11th Grade
•
Medium
Martin Dunn
Used 121+ times
FREE Resource
10 Slides • 9 Questions
1
Python - While Loops

2
While Loops
A while loop is a block of code that will keep repeating until a condition has been met.
3
Looping (Iteration)
Looping code in programming is called "Iteration"
You can re-use the same code over and over again.
This saves on the amount of code you have to write.
4
Example
This example asks you what the capital city of France is.
It keeps asking the same question if your answer is not Paris.
5
Multiple Choice
6
Multiple Choice
Why is iteration (looping) important?
It determines the order in which instructions are carried out
It allows code to be simplified by removing duplicated steps
It allows multiple paths through a program
It ensures the code works correctly
7
Conditions that cause and stop a loop.
Loops can sometime be stuck in an infinite loop
8
This can be fixed by asking for a user input for the variable "play" during each loop.
The loop will carry on if you type "yes" (meeting the condition)
Typing anything else will stop the loop.
9
Using a Counter
This loop will print out "Let's play" each time is runs.
After every loop, the counter increases by one.
It continue to loop while the counter is less than 5
What happens when the counter reaches 5?
10
Multiple Choice
How many times will this program print out "Let's play before the loop stops?"
4
5
0
9
11
Whay was the answer 5 times?
The counter for the loop begins at 0.
the looping happened when the counter was 0,1,2,3 and 4
12
Multiple Choice
How many times will this loop run before it exits?
3
5
4
10
13
Conditions
Equal to ==
Less than <
Greater Than >
Less than or equal to <=
Greater than or equal to >=
Not equal to !=
14
Multiple Choice
15
Multiple Choice
16
Multiple Choice
17
Multiple Choice
18
Multiple Choice
Which type of loop iterates (loops) until instructed otherwise?
FOR loop
A count-controlled loop
Repeat-once loop
WHILE loop
19
Using "break" to end a loop
In this example, the loop is still set to run 5 times.
On each loop you are asked the question "what is 2+2".
If you answer correctly, you are told "correct" and the loop breaks.
Python - While Loops

Show answer
Auto Play
Slide 1 / 19
SLIDE
Similar Resources on Wayground
14 questions
Geometry Review -Transformations
Presentation
•
8th - 10th Grade
14 questions
Electronic Symbols
Presentation
•
8th - 10th Grade
13 questions
Journalism 101
Presentation
•
8th - 10th Grade
13 questions
arithmetic sequences
Presentation
•
8th - 10th Grade
13 questions
Solving Systems of Equations Using Elimination
Presentation
•
8th - 10th Grade
15 questions
Add, Subtract and Multiply Radical Expressions
Presentation
•
9th - 11th Grade
13 questions
K.2 Pause for People
Presentation
•
KG
14 questions
Subject Pronouns
Presentation
•
8th - 12th Grade
Popular Resources on Wayground
24 questions
PBIS-HGMS Day 10
Quiz
•
6th - 8th Grade
10 questions
HCS SCI 03 Summer School Review 3
Quiz
•
3rd Grade
11 questions
Home Scope
Quiz
•
7th - 8th Grade
15 questions
HCS SCI 05 Summer School Assessment 3 Review
Quiz
•
5th Grade
35 questions
Lufkin Road Middle School Student Handbook & Policies Assessment
Quiz
•
7th Grade
18 questions
Geo 11.3 Area of Circles and Sectors
Quiz
•
9th - 11th Grade