/* Loops3.java CIS 111 Sept. 24, 2007 David G. Klick Demonstrates repetition and accumulators */ public class Loops3 extends CIS111App { public static void main(String[] args) { int i; int accum; println("This program adds up the numbers from 1 to 10" + " using different types of loops."); print("A do loop: "); i = 1; accum = 0; do { accum = accum + i; i = i + 1; } while (i <= 10); println(accum); // this is called a pre-test loop because the test // is at the beginning of the loop print("A while loop: "); i = 1; accum = 0; while (i <= 10) { accum = accum + i; i = i + 1; } println(accum); // the for loop is also a pre-test loop print("A for loop: "); accum = 0; for (i=1; i<=10; i++) { accum = accum + i; } println(accum); } }