- Forward


Sequential Loops
A Programming Pattern


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Motivation
Back SMYC Forward
  • A Review:
    • Loops allow us to repeat a step or sequence of steps multiple times
  • An Observation:
    • We can't always accomplish what we want/need to with a single loop
Using Multiple Loops
Back SMYC Forward
  • Nested:
    • One (or more) loops in the body of another loop
  • Sequential:
    • One (or more) loops following/after another loop
When the Need Arises
Back SMYC Forward
  • After Using an Accumulator:
    • Bigger/smaller than the average
    • Percent of the total/minimum/maximum
  • After Finding a Containing Interval:
    • Position within an interval
An Example
Back SMYC Forward
  • The Problem:
    • Display the elements of an array that are larger than the mean value
  • A Solution (using Sequential Loops):
    • javaexamples/programmingpatterns/SequentialLoopExample.java (Fragment: big)
       
There's Always More to Learn
Back -