// code from week 6 // if statements if (iq > 140) System.out.println("you are smart!"); if (iq <= 140) System.out.println("go study some more!"); // an equivalent if-else form if (iq > 140) System.out.println("you are smart!"); else System.out.println("go study some more!"); /**********************************************************/ // multiple ifs if (iq > 140) System.out.println("you are smart!"); else if (iq > 100) System.out.println("not bad!"); else System.out.println("go study some more!"); /**********************************************************/ // using blocks if (iq > 140) { System.out.println("you are smart "); System.out.println("and sexy!"); } else System.out.println("go study some more!"); /**********************************************************/ // nested ifs // WRONG: if (a > 0) if (a % 2 == 0) System.out.println(a + " is positive and even"); else System.out.println(a + "is negative"); // CORRECTED: if (a > 0) { if (a % 2 == 0) System.out.println(a + " is positive and even"); } else System.out.println(a + "is negative"); /**********************************************************/ // while loop examples int num=1; while (num <= 5) { System.out.println("Good day Sir!"); num++ if (num >= 3 && num < 5) System.out.print("I SAID... "); } // counting down int beers = 12; while (beers > 0) { System.out.println("there's still beer!"); beers--; System.out.println("one more down!"); } System.out.println("Dude, where's my beer?"); // dangerous conditions int i=0; while (i != 10) { System.out.println("Hey!"); i = i+2; } // How many times does "Hey!" show up on the screen? // it may surprise you.