/* Loops2.java CIS 111 Sept. 24, 2007 David G. Klick Demonstrates difference between pre-test and post-test loops Notice how the post-test loop's code executes one time even though the test will be false as soon as it is evaluated. The reason is that the test in a post-test loop doesn't get evaluated until the loop body has executed one time. */ public class Loops2 extends CIS111App { public static void main(String[] args) { int i; // this is called a post-test loop because the test // is at the end of the loop print("\nA do loop: "); i = 10; do { print(i + " "); i = i + 1; } while (i < 1); // this is called a pre-test loop because the test // is at the beginning of the loop print("\nA while loop: "); i = 10; while (i < 1) { print(i + " "); i = i + 1; } // the for loop is also a pre-test loop print("\nA for loop: "); for (i=10; i<1; i++) { print(i + " "); } } }