How to exclude zero in a for loop in Java

Posted by user1745508 on Stack Overflow See other posts from Stack Overflow or by user1745508
Published on 2012-10-15T03:31:10Z Indexed on 2012/10/15 3:36 UTC
Read the original article Hit count: 98

Filed under:
|

I'm trying to exclude the zero in this nested for loop here using != 0; but it is not doing anything. I'm trying to get the probability of each out come of 2 six sided dice when rolled. I must figure out the amount of times they are rolled first, but a die doesn't have a zero in it, so I must exclude it. I can't figure out why this doesn't work.

for( die2 = 0; die2 <= 6 && die2 != 0; die2++)
            for( die1 = 0; die1 <= 6 && die1 != 0; die1++)
                System.out.println("Die 2: " + (die2 * userInputValue) + " " + "Die 1: " +       (die1 * userInputValue));

© Stack Overflow or respective owner

Related posts about java

Related posts about nested-loops