// Some examples of for loops. public class DemonstrateLoops { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { System.out.println("Shave and a haircut,"); System.out.println("two bits"); } System.out.println(); // only 1 blank line printed for (int day = 1; day <= 12; day++) { System.out.println("On day #" + day + " of Christmas, my true love sent to me"); } System.out.println(); // using a table to map from count to desired output number: // // count output count * -4 count * -4 + 21 // 1 17 -4 17 // 2 13 -8 13 // 3 9 -12 9 // 4 5 -16 5 // 5 1 -20 1 // for (int count = 1; count <= 5; count++) { System.out.print(count * -4 + 21 + " "); } System.out.println(); // end the line of output System.out.println(); // nested loops to print a multiplication table for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 10; j++) { System.out.print((i * j) + " "); } System.out.println(); // end the line } // What happens if we move the println command outside // the outer loop? What if we move it into the inner j loop? } }