Lesson #8 Review Questions

Back to Lesson # 8 - Looping Table of Contents # 8 Assignment

 

 

1. Which type of looping construct is the best choice for having the computer calculate grade point averages for students with ID numbers 1000 to 1100?

for loop
pre-test loop (while (...) )
post-test loop ( do... while (...) )
pre-test with priming input
2. Which type of looping construct would be the best choice for prompting a user to enter the number of the bus they wish to ride, and repeating the prompt if the number of the bus is NOT between 1 and 24?

for loop
pre-test loop (while (...) )
post-test loop ( do{...} while(...) )
pre-test loop with a primimg input

3. Which of the following is the best choice for asking a user to decide whether they wanted to run a game program again or not?

for loop
pre-test loop (while (...) )
post-test loop ( do... while (...) )
pre-test with priming input
4. What is an infinite loop?
It is the size of the interrupt request to the system doing the processing.
A pre-test loop ( while (...) {...} ) where the loop condition is set to be true and the loop control variable is not changed within the loop body.
A post-test loop ( do {...} while (...) ) where the loop condition is set to be true and the loop control variable is not changed within the loop body.
Any loop that just repeats forever.

5. A do {...} while (...) loop will repeat until

The computer's memory buffers are full.
The user decides to quit.
The conditional expression is no longer true.
The "do" expression terminates

6. Some beginning programmers try to check the user's input for validity by using a branching structure. What is the drawback of using an if statement as shown in this example:

	...
	if (badData) userData = prompt("Invalid, Please re-enter your information."        ,""); 
Since the user's data was wrong the first time, it might be wrong the second time too, and the program just goes on to the next phase.
No problem, this method is just as good as using a loop
An if statement has the potential to utilize too much of the system's resources and crash the computer.
An if statement may corrupt the stack memory buffers.

7. What is the output of this code segment?

	var a=10,b=3;
	while ( a-b < 0 ) {
		document.write ("I am the greatest!");

		a-=b;

	}
"I am the greatest!" will print one time only.
"I am the greatest!" will print twice.
No output, since this loop will never execute.
"I am the greatest!" will print 3 times.
8. OBOB stands for
Out of Binary Output Bug
Overflow But Ongoing Bug
Off By One Bug
Olaf Buehll Overflow Bug

9. What is the output of this code?

	var tot = 0;
	for (var i = 0; i < 6; i++) {
		tot +=i;
	}
	alert ( "The total is now " + tot ); 

The total is now 15
The total is now 21
The total is now 10
The total is now 6

10. Which of these can be placed inside of the body of a loop?
If statements
Pre-test loops with priming input
Switch constructs that test a variable for any of a number of values.
Any of the above.

Return to Top of Page | Back to Main Menu