1) Why should you indent the statements in the body of a loop?
Because by indenting the statements in the body of the loop you visually set them apart from the surrounding code. This makes your program easier to read and debug
2) Describe the difference between pretest loops and posttest loops
A pretest loop means to test its condition before performing an iteration
A posttest loop means it performs an iteration before testing its condition
3) What is a condition-controlled loop?
A condition-controlled loop uses a true/false condition to control the number of times that it repeats
4) What is a count-controlled loop?
A count-controlled loop repeats a specific number of times
5) What three actions do count-controlled loops typically perform using the counter variable?
1) Initialization: the variable is initialized 2) Test: the loop tests the variable by comparing it to the maximum value 3) Increment: to increase the value during each iteration the loop increments the counter variable by adding 1 to it.
Algorithm Workbench Review Question
1) Design a While loop that lets the user enter a number. The number should be multiplied by 10, and the result stored in a variable named product. The loop should iterate as long as the product contains a value less than 100.
Declare product as integer
Declare number as integer
While product < 100
Display “What is your number”
Input number
Product = number *10
Display “Your number is “, product
End While
2) Design a Do-While loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The loop should ask the user if he or she wishes to perform the operation again. If so, the loop should repeat, otherwise it should terminate
Declare string again
Declare 1num as Real
Declare 2num as Real
Declare sumNum as real
Do Display “What is your first number” Input 1num = “” Display “What is your second number” Input 2num = “” sumNum = 1num+2num