how do I simplify this while loop? It doesn't seem to work when I put != 2 && 3 && 12.
Thank you
while (sum(diceRoll) != 2 && sum(diceRoll) !=3 && sum(diceRoll) !=12)
how do I simplify this while loop? It doesn't seem to work when I put != 2 && 3 && 12.
Thank you
while (sum(diceRoll) != 2 && sum(diceRoll) !=3 && sum(diceRoll) !=12)
Using the %in% operator, you could replace
while (sum(diceRoll) != 2 && sum(diceRoll) !=3 && sum(diceRoll) !=12)
by
while (!(sum(diceRoll) %in% c(2,3,12)))
The problem with your proposed solution is that 2 && 3 && 12 evaluates to TRUE so
while (sum(diceRoll) != 2 && 3 && 12)
parses as
while (sum(diceRoll) != TRUE)
which is functionally equivalent to
while (sum(diceRoll) != 1)
which is clearly not the intended meaning.