Lab 7: Prelab Questions

Write out your answers for these questions on a separate piece of paper.


Written Questions

Question #1: Which of the C++ loops is a pretest loop?

Question #2: Which of the C++ loops is a posttest loop?

Question #3: Which of the C++ loops provide both zero and one-trip behavior?

Question #4: Which of the C++ loops is best for counting?

Question #5: The ____________ statement allows you exit a loop in the middle.

Programming Exercises

Suppose that i and j are int variables initialized to some values.

Code #1: Write a while loop that repeats while i is less than j. Use an empty compound statement as the body of the loop.

Code #2: Write a do loop that repeats while i is less than j. Use an empty compound statement as the body of the loop.

Code #3: Write a counting for loop that counts from 4 to 55. Use an empty compound statement as the body of the loop.

Code #4: Write an if-break statement that breaks when i is less than j.

Code #5: Incorporate the if-break statement of the previous question into a forever loop. Use a compound statement as the body of the loop.


Lab Home Page | Lab Exercise | Homework Projects
© 2003 by Prentice Hall. All rights reserved.
Report all errors to Jeremy D. Frens.