Intro To Programming Lesson 4
Intro To Programming Lesson 4
Programming
Computer Science
Lesson 4
Unit 8.2
Objectives
- forever!
There are 3 types of Loops, we will start by looking at the first two:
- While Loops
- Do While Loops
- For Loops
While Loops
While Loops are controlled by a condition, the condition decides how many time it will loop!
Teacher jumps = 0
Show video
While Loops
While Loops are controlled by a condition, the condition decides how many time it will loop!
Teacher jumps = 0
Teacher jumps
Teacher jumps = 0
Teacher jumps
}
While Loops Example 2
While Loops are controlled by a condition, the condition decides how many time it will loop!
Laps = 0
What is happing in this While loop?
Score = 0
- What is the condition, when will the
While ( Laps < 50)
race stop?
{
- What happens to the Score on each
Continue Racing loop?
Score = Score +1 - What happens to the Laps on each
Laps = Laps +1 loop?
}
Do While Loops
Do While Loops are controlled by a condition, the condition decides how many time it will loop!
Teacher jumps = 0
}
The condition has moved here!
While (Teacher jumps < 5)
Reminder of Operators
Operators also allow
you to compare data
in programming,
which will also let
your program make
decisions.
Exercise 1