At the end of this lesson, you will be able to:
understand and use a do..while loop
With a pencil and paper, answer the following questions:
What is the purpose of a loop in computer programming?
What is the minimum number of times a WHILE loop will execute? Why?
Create a flowchart that does the following:
Initialize a variable called "product" to 1.
Initialize a variable called "counter" to 1.
Ask the user for a positive number.
ICS3U: Make sure your program does not crash.
Use a WHILE loop to calculate the product of all numbers from 1 to that number
Display the product to the user
while loops
execute a minimum of 0 times
from the online book Computer Based Problem Solving by Patrick Coxall, read:
Do..While Loops do NOT exist in Python
so we will modify have to do a modified while loop
Do..While Loops:
have a boolean expression at the END of the loop
have a counter that will be part of your condition to stop the loop.
The counter is initialized OUTSIDE the loop.
The counter is incremented/decremented INSIDE the loop.
execute at least once
An infinite loop occurs when the boolean expression never evaluates to false and therefore the loop goes on forever and your program crashes.
Write a program that asks the user to enter a whole number (i.e. 0, 1, 2, ..)
It then uses a do..while loop (this does not exist in Python so you need to improvise) to calculate the factorial of the number
Make sure your program does not crash if a user enters invalid input!
Note: This code does not do error checking!
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++
Note: This code does not have error checking!