Wyo Java Ch. 6 Lecture Notes

Objective #1: Explain the importance of loops in programs.

Objective #2: Use for loops.

for(initializing expression; control expression; step expression)
{

       one or more statements
}

Objective #3: Use while loops.

Objective #4: Use do while loops.

Objective #5: Use the break and continue statements with loops appropriately.

Objective #6: Use nested loops effectively when appropriate.

Objective #7: Use flag variables and sentinel values to control indeterminate loops.

Objective #8: Identify loop invariants.

Objective #9: Use random number generation to create simulations.

1  import java.util.Random;
2  
3  public class RandomNumbers
4  {
5     public static void main(String[] args)
6     {
7         Random dice = new Random();
8         int diceRoll = dice.nextInt(6) + 1;
9     }
10 }