Loops

New Terminology

pre-condition loop
A loop where the decision to continue occurs before the body of the loop is executed.
post-condition loop
A loop where the decision to continue occurs after the body of the loop is executed.
counted loop
A specific type of precondition loop which includes the initialization, condition, and update in the loop header structure
loop control variable(s)
One or more variables whose value(s) determine how long the loop will continue.
sentinel (sentinel value)
A value which is used to stop (or continue) loop execution.
flag
A boolean value that flags the end condition of a loop execution
accumulator
A variable that serves to accumulate a series of values.  Usually used in summation, but may be used for any repeated operation.
initialization
For loops, this is the place where we set-up one or more variables that will be used to control loop execution.
decision
For loops, this determines how long the loop will continue to execute.
update
For loops, this step changes the loop control variables to approach the ending condition.
body
For loops, this is the code that may repeatedly execute.

Java Specific Terms

while loop
A precondition loop in java
do while loop
A post condition loop in java
for loop
A precondition, counting loop in java
increment operator (++)
decrement operator (--)
Unary operation that adds or subtracts one from the operand. (Ex: counter++;). May be prefix or postfix, but convention is postfix. Do not use except as a statement by themselves.

Class notes

  1. Review  lab (Student.java and Grades.java)
  2. PA2 - Choices - which of these choices are the best.  Rank order?
    1. Do the entire pa correctly
    2. Do the entire pa half way (errors, typos)
    3. Do part of the pa correctly
    4. Do the entire pa but turn it in late
  3. Introduce the concept of loops
  4. Why do we care?
  5. Types of loops Slides

    - pre-condition (while) - LoopWhile.java

    - post-condition - LoopDo.java

    - counted - LoopFor.java

    Most loops include:

    - setup or initialization

    - decision

    - body of actions

    - update

  6. Book examples of loops (referenced in slides)

    - WhileLoop.java

    - TestAverage1.java

    - Squares.java

    - UserSquares.java

    - TotalSales.java