At the end of this lesson, you will be able to:
understand and use a break statement inside a loop
With a pencil and paper, answer the following questions:
What is the minimum number of times a FOR loop will execute? Why?
Which other loop is a FOR loop most similar to? Why?
Write the code for a for loop in Python that does the following:
Display all the even numbers, one per line, from -20 to 40.
What is displayed to the console by the following code:
for loops
in Python:
for counter in range (user_num + 1):
OR
for counter in range(-5, user_num + 1):
OR
for counter in range(2, user_num + 1, 3):
in C++:
for (counter initialization; boolean expression; counter increment/decrement) {
...
}
from the online book Computer Based Problem Solving by Patrick Coxall, read:
used to break out of a loop when a boolean condition is triggered
Write a program that generates a random correct guess between 0 and 9.
It then uses a while TRUE loop to keep asking the user to guess the number until they guess correctly.
It uses a break statement to exit the loop once they guess the correct number.
Make sure your program does not crash if a user enters invalid input!
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++