mercredi 29 avril 2015

Incrimenting value DOWN wont print out

Having an issue printing the results of i when I'm incrementing DOWN starting from startVal and ending at endVal with an increment of incVal.

the first if statement is printing correctly and I had THOUGHT that the second else if statement should be fairly similar however even though my original values; for EX: if startVal = 100, endVal = 10, and incVal = -1, it jumps to the else if statement correctly (tested with a basic print statement) but the for loop doesn't seem to work and not print out the results of i like it should.

                if ((startVal < endVal)  &&  (incVal >= 1))
                {  
                     for (int i = startVal; i <= endVal; i += incVal)
                     {
                          System.out.println(i);
                     }

                }
                //  else if incrimenting down
                else if((startVal > endVal)  &&  (incVal <= -1))
                {
                     for (int i = startVal; i <= endVal; i -= incVal)
                     {
                          System.out.println(i);
                     }

                }

Is there something stupid I'm messing up here? I've tried different things inside the for loops to get i to print but it doesn't work the correct way..

Aucun commentaire:

Enregistrer un commentaire