At the end of this lesson, you will be able to:
A2.3 write algorithms with nested structures (e.g., to count elements in an array, calculate a total, find highest or lowest value, or perform a linear search).
understand and use a nested loop
With a pencil and paper, answer the following questions:
What is the purpose of a continue statement?
Where can be put a continue statement?
Create the pseudocode for a looping program that does the following:
Ask the user to enter a mark
If they enter a value that is not a mark, continue
If they enter "q", break
Calculate the sum of the marks entered
Once they quit, calculate and display the average
The following program is supposed to display the total number of positive integers entered. Fix the 4 errors in the code. (Don't worry about error checking.)
continue statements
used to skip over part of a loop
from the online book Computer Based Problem Solving by Patrick Coxall, read:
show demo of nested loop odometer using PyBadge
Write a program uses nested loops to print out all valid RGB colours!
You will need 3 loops in total.
To display each line in the colour it reflects, do the following:
in Python:
in C++:
For example:
RGB (0, 0, 0)
RGB (0, 0, 1)
...
RGB (0, 0, 255)
RGB (0, 1, 0)
RGB (0, 2, 0)
...
RGB (0, 255, 0)
RGB (1, 0, 0)
RGB (2, 0, 0)
...
RGB (255, 0, 0)
used to represent colours
their values go from 0 to 255 (the highest value in 1 byte)
look at the RGB Color Codes Chart to see how each Red, Green & Blue change for each colour
Black = (0, 0, 0) meaning 0 Red, 0 Green and 0 Blue
White = (255, 255, 255) meaning 255 Red, 255 Green and 255 Blue
Try entering: (153, 51, 255)
This makes purple!
in groups of 2, do the following on the board for today's daily assignment:
Top-Down Design
Flow Chart
Pseudocode
Test Cases
complete the Daily Assignment section in Hãpara Workspace for this day
if Hãpara is not working, make a copy of this document
move it to your IMH-ICS folder for this course
recreate the same program in C++
OR, use your PyBadge and rotate through the RGB colours on the Neopixels
click here to see the code
you will also need to include the "lib" folder on your PyBadge and place the neopixel.mpy file inside the "lib" folder