
![[IGCS] Counting Loop](https://cf.quizizz.com/img/presentation/default-img/presentation_title_img-1_default.jpg?w=200&h=200)
[IGCS] Counting Loop
Presentation
•
Computers
•
9th Grade
•
Easy
Andy tsui
Used 2+ times
FREE Resource
9 Slides • 11 Questions
1
[IGCS] Counting Loop

2
There are mainly two types of loops
Conditional loops - Number of time is indefinite
Counting loops - Loop with a definite number of times
3
Open Ended
What are the two types of condition loops?
4
Counting
counter <- 0
WHILE counter < 10 DO
⠀# do something....
⠀counter <- counter + 1
ENDWHILE
5
For loop
# The previous slide's counting algorithm can be rewrite using for loop:
FOR counter <- 0 to 9 DO
⠀# Do something
NEXT counter
6
Multiple Choice
If we write:
FOR counter <- 0 to 5 DO
PRINT counter
NEXT counter
What will be the last number to print?
0
4
5
6
7
FOR [count_var] <- [start] to [stop] DO
count_var the variable that used as counter, usually we use counter or i, j, k to name counter
start: the value that the count_var is initialized with. In other word, count_var = start when the loop is first executed
stop: the loop ends when counter reaches stop value.
i.e. count_var = stop when the last time the loop run
8
Python for loop is a bit different
# In Python
for counter in range(0, 10):
⠀print(counter)
# implies that the counter is counting from 0 to 9 (not including 10)
# so the above code will print from 0 - 9 only
9
Open Ended
Describe what is the following program produce:
FOR i <- 10 to 1 DO
⠀PRINT i
NEXT i
10
For the previous program, it will be:
for i in range(10, 0, -1):
⠀print(i)
# when coding in Python
11
12
Multiple Choice
What is the range of the value (inclusive) if we write:
range(5)
1..5
0..5
0..4
1..4
13
Multiple Choice
What is the range of the value (inclusive) if we write:
range(0, 5)
1..5
0..5
0..4
1..4
14
Multiple Choice
What will be the sequence of number generated if we write:
range(1, 5, 1)
1 2 3 4 5
0 1 2 3 4 5
0 1 2 3
1 2 3 4
15
Multiple Choice
What will be the sequence of number generated if we write:
range(0, 5, 2)
0 1 2 3 4
0 1 2 3 4 5
0 2 4
0 2 4 6
16
Multiple Choice
What will be the sequence of number generated if we write:
range(3, 0, -1)
0 1 2 3
0 1 2
3 2 1 0
3 2 1
17
Open Ended
Write the range() function to generate 0-5 (inclusive)
18
Open Ended
Write the range() function to generate even numbers from 0-10 (inclusive)
19
Multiple Select
** Which of the following program(s) print first 5 odd numbers?
for i in range(10):
print(i*2 + 1)
for i in range(1, 9, 2):
print(i)
for i in range(1, 11, 2):
print (i)
for i in range(1, 10, 2):
print(i)
for i in range(0,5,2):
print(i*2 + 1)
20
Summary
Use For-loop when the number of times is definite
The counter range can be customized by specifying: start, end and interval
[IGCS] Counting Loop

Show answer
Auto Play
Slide 1 / 20
SLIDE
Similar Resources on Wayground
15 questions
Noun
Lesson
•
9th Grade
16 questions
present perfect tense
Lesson
•
9th Grade
16 questions
Types of Slopes
Lesson
•
9th Grade
16 questions
CP - Lesson: Function Notation (Part 1)
Lesson
•
9th Grade
16 questions
Completing the square
Lesson
•
9th Grade
16 questions
Review of Quadratic Functions
Lesson
•
9th Grade
16 questions
Interactive Lesson Quadratic Function Transformation
Lesson
•
9th Grade
Popular Resources on Wayground
15 questions
Fractions on a Number Line
Quiz
•
3rd Grade
14 questions
Boundaries & Healthy Relationships
Lesson
•
6th - 8th Grade
13 questions
SMS Cafeteria Expectations Quiz
Quiz
•
6th - 8th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
25 questions
Multiplication Facts
Quiz
•
5th Grade
12 questions
SMS Restroom Expectations Quiz
Quiz
•
6th - 8th Grade
20 questions
Main Idea and Details
Quiz
•
5th Grade
10 questions
Pi Day Trivia!
Quiz
•
6th - 9th Grade
Discover more resources for Computers
10 questions
Pi Day Trivia!
Quiz
•
6th - 9th Grade
15 questions
Pi Day Trivia!
Quiz
•
9th Grade
15 questions
Pi Day Trivia
Quiz
•
9th - 12th Grade
10 questions
Understanding Pi and Its Applications
Interactive video
•
7th - 12th Grade
10 questions
Cell Organelles and Their Functions
Interactive video
•
6th - 10th Grade
20 questions
Graphing Inequalities on a Number Line
Quiz
•
6th - 9th Grade
5 questions
Did You Know? Ireland
Interactive video
•
9th - 10th Grade
10 questions
Exploring Basic Probability Concepts
Interactive video
•
6th - 10th Grade