/* Loops2.java CIS 160 David Klick 2004-09-17 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 { 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 System.out.print("\nA do loop: "); i = 10; do { System.out.print(i + " "); i++; } while (i < 1); // this is called a pre-test loop because the test // is at the beginning of the loop System.out.print("\nA while loop: "); i = 10; while (i < 1) { System.out.print(i + " "); i++; } // the for loop is also a pre-test loop System.out.print("\nA for loop: "); for (i=10; i<1; i++) { System.out.print(i + " "); } } }