title: How to make a do...while loop with an if-else statement in java?
body: <p>I was given this assignment:</p>
  
  <p>"Write a program (Blueberry.java) that uses a while loop to print the integers 1 to 100, one number on each line, and set the number’s field width as 3. When a number is divisible by 3, print “Blue” on the same line, and separate them by a space. Follow the same format, when a number is divisible by 5, print “Berry”; and when a number is divisible by 15, print “Blueberry”.  Note that a number divisible by 15 will also be divisible by 3 and 5. In this case, only “Blueberry” should be printed.  A message, “The following is from a while loop”, should be printed on the first line. Three messages, one on each line, should be printed to report the total numbers of “Blue”, “Berry”, and “Blueberry” respectively. Finally, in the same program, add a for loop and a do…while loop: each accomplishes the same task as the while loop."
  I've figured out the while loop and the for loop, but I'm having trouble with the do...while loop. </p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class Blueberry {
      public static void main(String[] args) {
          Scanner input = new Scanner(System.in);
  
          System.out.println("The following is from a while loop: ");
          int blueCount = 0;
          int berryCount = 0;
          int blueberryCount = 0;
  
          int i = 1; 
          while(i &lt;= 100){
              if(i % 3 == 0 &amp;&amp; i % 5 == 0) {
                  System.out.printf("%3d %s\n",  i, "Blueberry");    
                  blueberryCount++;
              }
              else if(i % 3 == 0) {
                  System.out.printf("%3d %s\n",  i, "Blue");    
                  blueCount++;
              }
              else if(i % 5 == 0) {
                  System.out.printf("%3d %s\n",  i, "Berry");    
                  berryCount++;
              }
              else {
              System.out.printf("%3d\n", i);
              }
              i++;
          }
          System.out.printf("There are %d Blues. \n",  blueCount);
          System.out.printf("There are %d Berries. \n",  berryCount);
          System.out.printf("There are %d Blueberries. \n",  blueberryCount);
          System.out.println();
  
          blueCount = 0;
          berryCount = 0;
          blueberryCount = 0;
  
          System.out.println("The following is from a for loop: ");
          for (i = 1; i &lt;= 100; i++) {
              if(i % 3 == 0 &amp;&amp; i % 5 == 0) {
                  System.out.printf("%3d %s\n",  i, "Blueberry");
                  blueberryCount++;
              }
              else if(i % 3 == 0) {
                  System.out.printf("%3d %s\n",  i, "Blue");
                  blueCount++;
              }
              else if(i % 5 == 0) {
                  System.out.printf("%3d %s\n",  i, "Berry"); 
                  berryCount++;
              }
              else {
              System.out.printf("%3d\n", i);
  
                  }
              }
              System.out.printf("There are %d Blues. \n",  blueCount);
              System.out.printf("There are %d Berries. \n",  berryCount);
              System.out.printf("There are %d Blueberries. \n",  blueberryCount);
              System.out.println();
  
              blueCount = 0;
              berryCount = 0;
              blueberryCount = 0;
  
              System.out.println("The following is from a do...while loop: ");
              do {
                  if(i % 3 == 0 &amp;&amp; i % 5 == 0) {
                      System.out.printf("%3d %s\n",  i, "Blueberry");    
                      blueberryCount++;
                  }
                  else if(i % 3 == 0) {
                      System.out.printf("%3d %s\n",  i, "Blue");    
                      blueCount++;
                  }
                  else if(i % 5 == 0) {
                      System.out.printf("%3d %s\n",  i, "Berry");    
                      berryCount++;
                  }
                  else {
                  System.out.printf("%3d\n", i);
                  }
                  i++;
                  }
  
              while (i &lt;= 100);
      }
  }
  
  
  
  
  
  
  
  
  and this is what it looks like when I run it:
  </code></pre>
  
  <p>The following is from a while loop: </p>
  
  <pre><code> 1
    2
    3 Blue
    4
    5 Berry
    6 Blue
    7
    8
    9 Blue
   10 Berry
   11
   12 Blue
   13
   14
   15 Blueberry
   16
   17
   18 Blue
   19
   20 Berry
   21 Blue
   22
   23
   24 Blue
   25 Berry
   26
   27 Blue
   28
   29
   30 Blueberry
   31
   32
   33 Blue
   34
   35 Berry
   36 Blue
   37
   38
   39 Blue
   40 Berry
   41
   42 Blue
   43
   44
   45 Blueberry
   46
   47
   48 Blue
   49
   50 Berry
   51 Blue
   52
   53
   54 Blue
   55 Berry
   56
   57 Blue
   58
   59
   60 Blueberry
   61
   62
   63 Blue
   64
   65 Berry
   66 Blue
   67
   68
   69 Blue
   70 Berry
   71
   72 Blue
   73
   74
   75 Blueberry
   76
   77
   78 Blue
   79
   80 Berry
   81 Blue
   82
   83
   84 Blue
   85 Berry
   86
   87 Blue
   88
   89
   90 Blueberry
   91
   92
   93 Blue
   94
   95 Berry
   96 Blue
   97
   98
   99 Blue
  100 Berry
  There are 27 Blues. 
  There are 14 Berries. 
  There are 6 Blueberries. 
  </code></pre>
  
  <p>The following is from a for loop: </p>
  
  <pre><code> 1
    2
    3 Blue
    4
    5 Berry
    6 Blue
    7
    8
    9 Blue
   10 Berry
   11
   12 Blue
   13
   14
   15 Blueberry
   16
   17
   18 Blue
   19
   20 Berry
   21 Blue
   22
   23
   24 Blue
   25 Berry
   26
   27 Blue
   28
   29
   30 Blueberry
   31
   32
   33 Blue
   34
   35 Berry
   36 Blue
   37
   38
   39 Blue
   40 Berry
   41
   42 Blue
   43
   44
   45 Blueberry
   46
   47
   48 Blue
   49
   50 Berry
   51 Blue
   52
   53
   54 Blue
   55 Berry
   56
   57 Blue
   58
   59
   60 Blueberry
   61
   62
   63 Blue
   64
   65 Berry
   66 Blue
   67
   68
   69 Blue
   70 Berry
   71
   72 Blue
   73
   74
   75 Blueberry
   76
   77
   78 Blue
   79
   80 Berry
   81 Blue
   82
   83
   84 Blue
   85 Berry
   86
   87 Blue
   88
   89
   90 Blueberry
   91
   92
   93 Blue
   94
   95 Berry
   96 Blue
   97
   98
   99 Blue
  100 Berry
  There are 27 Blues. 
  There are 14 Berries. 
  There are 6 Blueberries. 
  </code></pre>
  
  <p>The following is from a do...while loop: 
  101</p>
  
  <p>What am I doing wrong with the do...while loop?</p>