Wednesday, October 1, 2008

Gettin' Loopy

Today we had our first encounter with loops in the form of the while and the do...while loop. (pp 131-134 in the text) Here are a couple of things to remember about loops:

  • the body of the loop (which can be one statement or many) keeps executing repeatedly (i.e. looping) while the loop condition remains true.
  • the loop condition is the same type of Boolean expression as you find in the if and if...else statements
  • the loop condition is evaluated (to see if it's still true or not) every time the loop iterates
  • when the loop condition turns to false the loop stops executing and the program continues with the next statements after the loop
  • an improperly formed loop can iterate infinitely. (Bad, bad, programmer.)
Tomorrow we're going to talk about the for loop which is useful for iterating when the maximum or minimum number of iterations is known ahead of time. We'll also be talking about some debugging techniques that you can use to fix problems in longer programs.

Homework for today? Why, yes, glad you asked. P149, Qs3, 5, and 6.

No comments: